Xcode Error: Command failed due to signal: Segmentation fault: 11 - xcode

I am getting an error "Command failed due to signal: Segmentation fault: 11" at runtime. I believe this is a compile error because when I clean my code it does not have any errors, only when I run & build. I am using the new Xcode beta 7.1. I also built it through my Xcode 7.0 but received same error.
The Swift code has previously built with no errors. This code is dealing with a Parse backend and querying some info to display to a user; here is the logs below:
1. While type-checking 'viewDidLoad' at /Users/User/Documents/Documents/ProjectName/UserProfile.swift:27:14
2. While type-checking expression at [/Users/User/Documents/Documents/ProjectName/UserProfile.swift:34:9 - line:55:9] RangeText="query.findObjectsInBackgroundWithBlock {
(objects: [AnyObject]?, error: NSError?) -> Void in
if error == nil {
if let objects = objects as? [PFObject] {
for object in objects {
let userImageFile: PFFile = object.objectForKey("ProfPhoto") as! PFFile
userImageFile.getDataInBackgroundWithBlock {
(imageData: NSData?, error: NSError?) -> Void in
if error == nil {
if let imageData = imageData {
self.ProfileImage.image = UIImage(data:imageData)
}
}
}
}
}
} else {
// Log details of the failure
print("Error: \(error!) \(error!.userInfo)")
}
}"
3. While type-checking expression at [/Users/User/Documents/Documents/ProjectName/UserProfile.swift:34:9 - line:55:9] RangeText="query.findObjectsInBackgroundWithBlock {
(objects: [AnyObject]?, error: NSError?) -> Void in
if error == nil {
if let objects = objects as? [PFObject] {
for object in objects {
let userImageFile: PFFile = object.objectForKey("ProfPhoto") as! PFFile
userImageFile.getDataInBackgroundWithBlock {
(imageData: NSData?, error: NSError?) -> Void in
if error == nil {
if let imageData = imageData {
self.ProfileImage.image = UIImage(data:imageData)
}
}
}
}
}
} else {
// Log details of the failure
print("Error: \(error!) \(error!.userInfo)")
}
}"
4. While type-checking expression at [/Users/User/Documents/Documents/ProjectName/UserProfile.swift:34:48 - line:55:9] RangeText="{
(objects: [AnyObject]?, error: NSError?) -> Void in
if error == nil {
if let objects = objects as? [PFObject] {
for object in objects {
let userImageFile: PFFile = object.objectForKey("ProfPhoto") as! PFFile
userImageFile.getDataInBackgroundWithBlock {
(imageData: NSData?, error: NSError?) -> Void in
if error == nil {
if let imageData = imageData {
self.ProfileImage.image = UIImage(data:imageData)
}
}
}
}
}
} else {
// Log details of the failure
print("Error: \(error!) \(error!.userInfo)")
}
}"

I've searched why The error: "Command failed due to signal: Segmentation fault: 11" is causing problems in my app... My app is Parse dependent. I found out that Parse made changes to method:
query.findObjectsInBackgroundWithBlock({ (objects : [AnyObject]?, error : NSError?) -> Void in
to
query.findObjectsInBackgroundWithBlock({ (objects : [**PFObject**]?, error : NSError?) -> Void in
I've changed it all, and now it works. Hope this will help someone using Parse. Thanks to user Babac.

The good answer for this question is to change the methode :
query.findObjectsInBackgroundWithBlock({ (objects : [PFObject]?, error : NSError?) -> Void in
to this :
query.findObjectsInBackgroundWithBlock({ (objects : [AnyObject]?, error : NSError?) -> Void in
because the only thing to change is [PFObject]? to [AnyObject]? then your code will work fine ;-)

Related

Swift 3 - Invalid conversion from throwing function type '(Any) -> Void'

I'm new to swift and
I'm not understanding why I'm getting this error.
I've being reading similar questions and so far none of them solved this error or I have not found it:
Invalid conversion from throwing function of type '(_) throws -> ()'
to non-throwing function type '(Any) -> ()'
At the line:
self.ws.event.message = { message in
The piece of code with the error:
public var ws = WebSocket()
public func websocket(token: Any){
self.ws.open("ws://"+String(APIHOST)+":"+String(port)+"/ws?token="+String(describing: token))
self.ws.event.message = { message in
if let text = message as? String {
let json = try JSONSerialization.jsonObject(with: text, options: []) as? [String: Any]
print("recv: \(text)")
}
}
}
Thanks for any help
Try below piece of code
public var ws = WebSocket()
public func websocket(token: Any){
self.ws.open("ws://"+String(APIHOST)+":"+String(port)+"/ws?token="+String(describing: token))
self.ws.event.message = { message in
if let dataObj = message as? Data {
do {
let json = try JSONSerialization.jsonObject(with:dataObj, options: []) as? [String: Any]
print("recv: \(text)")
} catch error {
print("Unable to load data: \(error)")
}
}
}
}
If you have a function that throws something, it usually means there might be a chance of error when accessing that data in your case JSON.
If function throws you need to do {} catch {} to tell Swift you are going to handle an error.

AFNetworking 3 and Swift 2- Cannot convert value NSURLSessionDataTask

When trying to access the GET function from AFHTTPSessionManager from , I get error, inputing the operation:
"Cannot convert value of type '(NSURLSessionDataTask!, AnyObject!) -> Void' to expected argument type '((NSURLSessionDataTask, AnyObject?) -> Void)?'"
return self.GET("search", parameters: parameters, success: {(operation:NSURLSessionDataTask!, response:AnyObject!) -> Void in
let dictionaries = response["businesses"] as? [NSDictionary]
if dictionaries != nil {
completion(Business.businesses(array: dictionaries!), nil)
self.appDelegate.businessesLoaded = true
}
}, failure: { (operation: AFHTTPSessionManager?, error: NSError!) -> Void in
completion(nil, error)
})!
AFHTTPSessionManager.m GET function:
- (NSURLSessionDataTask *)GET:(NSString *)URLString
parameters:(id)parameters
success:(void (^)(NSURLSessionDataTask *task, id responseObject))success
failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure
{
return [self GET:URLString parameters:parameters progress:nil success:success failure:failure];
}
This all used to work with AFHTTPRequestOperation, which is no longer part of AFNetworking 3 from deprecated NSURLConnection. Hope someone can shed some light on this and thank you very much in advance!

Swift 2 error handling - callback and image saving with Parse

I have tried the conversion tools to update these few lines of code, but unfortunately the process did not caught up these two errors.
Could you help me to understand if I need to introduce the do { and error handling? (I am new to swift!).
The error message I receive is the following: "Call can throw, but it is not marked with 'try' and the error is not handled"
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
query.findObjectsInBackgroundWithBlock {(result: [PFObject]?, error: NSError?) -> Void in
self.posts = result as? [Post] ?? []
// 1
for post in self.posts {
// 2
let data = post.imageFile?.getData() --> this is where I get the error message
// 3
post.image = UIImage(data: data!, scale:1.0)
}
self.tableview.reloadData()
}
Insted of this: let data = post.imageFile?.getData()
Use this instead:
do
{
try let data = post.imageFile?.getData()
}
catch
{
print("Error: \(error)")
//Handle the error instead of print probably
}

SWIFT + Parse signUpInBackgroundWithBlock no longer works: Xcode 6.3.1 [duplicate]

This question already has answers here:
Parse SDK methods not working in Xcode 6.3 Beta
(5 answers)
Closed 7 years ago.
I'm using the latest parse code from the parse.com for user.signupInBackgroundWithBlock
user.signUpInBackgroundWithBlock {
(succeeded: Bool?, error: NSError?) -> Void in
if let error = error {
let errorString = error.userInfo?["error"] as? NSString
self.showAlertWithText(message: "\(error)")
} else {
self.performSegueWithIdentifier("createNewUserAndGoToDashboard", sender: self)
}
I just upgraded to x-code 6.3.1 and it no longer works. This is copied directly from Parse.com, but I'm getting an error on the user.signUp line:
1.0/SIgnUpViewController.swift:48:46: Function signature '(Bool?, NSError?) -> Void' is not compatible with expected type
'#objc_block (Bool, NSError!) -> Void'
any tips?
have you tried it without the "?" after the Bool
user.signUpInBackgroundWithBlock {
(succeeded: Bool, error: NSError?) -> Void in
if let error = error {
let errorString = error.userInfo?["error"] as? NSString
self.showAlertWithText(message: "\(error)")
} else {
self.performSegueWithIdentifier("createNewUserAndGoToDashboard", sender: self) }
Try this.
user.signUpInBackgroundWithBlock { (returnedResult, returnedError) -> Void in
if returnedError == nil
{
self.dismissViewControllerAnimated(true, completion: nil)
}
else
{
self.showAlert("There was an error with your sign up", error: returnedError!)
}
}

Signing Up Parse User with Swift 1.2

I use the signing up feature of Parse.com just as describe here. Here's my code:
user.signUpInBackgroundWithBlock {
(succeeded: Bool!, error: NSError!) -> Void in
if error == nil {
// Hooray! Let them use the app now.
} else {
let errorString = error.userInfo["error"] as NSString
// Show the errorString somewhere and let the user try again.
}
}
}
Unfortunately, I've updated my project from swift 1.1 to swift 1.2 and get the following compiler error:
Function signature '(Bool!, NSError!)->void is not compatible with
excepted type '#objc_block (Bool,NSError!)->Void'
it's on the following line:
user.signUpInBackgroundWithBlock {
(succeeded: Bool!, error: NSError!) -> Void in
Does anybody know how can I fox that ? Thanks !
Your succeeded variable is a 'Bool!' but what the block returns is a 'Bool' (without exclamation mark).
The solution would be:
user.signUpInBackgroundWithBlock {
(succeeded: Bool, error: NSError!) -> Void in
if error == nil {
// Hooray! Let them use the app now.
} else {
let errorString = error.userInfo["error"] as NSString
// Show the errorString somewhere and let the user try again.
}
}
}
Too see more about optionals go to the apple doc
I had the same problem with save in background with block. It looks like parse returns a "Bool not a Bool!"...however error is an NSError? unless you "!" it.
something.saveInBackgroundWithBlock {
(succeeded: Bool, error: NSError?) -> Void in
code
}

Resources