Parse signup error with swift 2 (xcode 7 beta 5) - ios

I am using Parse and I have a signup page where I call:
user.signUpInBackgroundWithBlock { (succeeded: Bool, error: NSError?) -> Void in
I checked and this works on previous versions of Xcode, however there was a similar problem when Swift 1.2 came out, though it doesn't solve my problem.
The error I get is:
Cannot invoke 'signupInBackgroundWithBlock' with an argument list of type: '((Bool, NSError?) -> Void )'
I'd be grateful for any help.

You should change the type of succeeded value to ObjCBool. The signature of PFBooleanResultBlock now changed (Bool, NSError?) -> Void to (ObjCBool, NSError?) -> Void
So you should change the type Bool to ObjCBool, like below:
user.signUpInBackgroundWithBlock { (succeeded: ObjCBool, error: NSError?) -> Void in
print(succeeded)
print(error)
}
or just remove the type to make the compiler inferring the type.
user.signUpInBackgroundWithBlock { (succeeded, error) -> Void in
print(succeeded)
print(error)
}

Related

Cannot assign value of type '(String?, Bool, [AnyObject]?, NSError?) -> ()' to

After I update Xcode Version 8.0 (8A218a) swift 3, I got this error
Cannot assign value of type '(String?, Bool, [AnyObject]?, NSError?) -> ()' to type 'UIActivityViewControllerCompletionWithItemsHandler?'
activityview.completionWithItemsHandler = {(activityType: String?, completed:Bool, returnedItems:[AnyObject]?, error: NSError?) in
if !completed {
print("cancelled")
return
}else{
complele()
}
}
I have been following this Cannot assign a value of type '(String!, Bool, [AnyObject]!, NSError!)->Void to a value of type UIActivityViewControllerCompletionWithItemsHandler?'
But i still got the error message.
It works well in previous version 7.3.1 swift 2.
Use UIActivityType instead of String, [Any] instead of [AnyObject] and Error instead of NSError like this.
activityview.completionWithItemsHandler = {(activityType: UIActivityType?, completed:Bool, returnedItems:[Any]?, error: Error?) in
if !completed {
print("cancelled")
return
}else{
complele()
}
}
Check apple documentation for more detail.

Unable to perform functions from Particle iOS Cloud SDK after downloading Xcode 8 / Swift 3.0

Prior to downloading Xcode 8 I was able to perform functions from the Particle iOS Cloud SDK (Spark SDK) without any problem. Now, I am being given multiple errors all similar to the ones below.
SparkCloud.sharedInstance().loginWithUser(username!, password: password!) { (error:NSError?) -> Void in
// Deactivates activity indicator.
activityIndicator.stopAnimating()
// Reallows interaction events.
UIApplication.sharedApplication().endIgnoringInteractionEvents()
if error != nil {
Utils.showAlertOnVC(self, title: "Invalid parameters.", message: "Please try again.")
self.clearText()
} else {
self.performSegueWithIdentifier("loginUser", sender: self)
}
}
Error: Cannot convert value of type '(NSError?) -> Void' to expected argument type 'SparkCompletionBlock?'
SparkCloud.sharedInstance().getDevices { (sparkDevices: [AnyObject]?, error: NSError?) -> Void in
if let sparkDevices = sparkDevices as? [SparkDevice] {
for device in sparkDevices {
self.myPhotons.append(device)
self.tableView.reloadData()
}
}
}
Error: Cannot convert value of type '([AnyObject]?, NSError?) -> Void' to expected argument type '(([Any]?, Error?) -> Void)?'
I've tried updating my Podfile and toying with the function calls but nothing seems to work. I'm wondering if it has something to do with the updates in Swift 3.0 but I can't find anything that would indicate so. Any help with this issue would be much appreciated.
Instead of NSError, use Error:
SparkCloud.sharedInstance().getDevices { (sparkDevices: [AnyObject]?, error: Error?)
This did the trick for me.

Xcode 8 Beta 6: storeViewController.loadProduct

What could be wrong with this line in Swift 3 that causes trying to build the app to fail...
storeViewController.loadProduct(withParameters: productparameters, completionBlock: { (success: Bool, error: NSError?) -> Void in
})
I am not getting an error shown on that line. I am getting the "Command failed due to signal: Segmentation fault: 11" error. Within that error's log it points me to the line:
2. While type-checking expression at [/Users/MyApp/MyViewController.swift:327:13 - line:331:14] RangeText="storeViewController.loadProduct(withParameters: productparameters, completionBlock: { (success: Bool, error: NSError?) -> Void in
})"
If I comment that line out, the app builds and runs without problem.
The lines that come before it:
let storeViewController:SKStoreProductViewController = SKStoreProductViewController();
storeViewController.modalPresentationStyle = .pageSheet
storeViewController.delegate = self;
self.present(storeViewController, animated: true, completion: nil);
let productparameters = [SKStoreProductParameterITunesItemIdentifier:idString, SKStoreProductParameterAffiliateToken:affString, SKStoreProductParameterCampaignToken:campString];
Replacing NSError with Error was the solution for me at this time.
storeViewController.loadProduct(withParameters: productparameters, completionBlock: { (success: Bool, error: Error?) -> Void in
})

Getting Error with PFAnonymousUtils.logIn

The Code below returns an error:
Cannot Covert value of type '(PDUser!, NSError!) -> Void' to expected argument type 'PFUserResultBlock'
PFAnonymousUtils.logIn{ (user: PFUser?, error: NSError?) -> Void in
if let user = user {
if user != nil {
println("Success")
}
} else {
println("Failed")
}
}
I looked at a few examples below for reference to see if there was a solution:
(1)Parse Facebook logInInBackgroundWithReadPermissions
(2)PFFacebookUtils login background cannot convert value to PFUserResultBlock
(3) iOS Developers Guide
The type inference is being thrown off. Try without the types. So PFAnonymousUtils.logIn{ (user, error) in This might fix it.
So With some help here's a complete solution:
Taking a suggestion where I would have to place :
PFAnonymousUtils.logIn{ (user, error) in
over
PFAnonymousUtils.logIn{ (user: PFUser?, error: NSError?) -> Void
the next error would be this line:
if let user = user {
where the compiler assumes that this isn't an optional, so the final solution in code would be
PFAnonymousUtils.logIn{ (user, error) in
if error == nil {
print("Success")
}
else {
print("Failed")
}
}
This way, it checks for an error, if there is an error, the code will print a line indicating as such.

Parse SDK methods not working in Xcode 6.3 Beta

So far I am having issues with blocks like this:
user.signUpInBackgroundWithBlock {
(succeeded: Bool!, error: NSError!) -> Void in
if error == nil {
println("success")
} else {
println("\(error)");
// Show the errorString somewhere and let the user try again.
}
}
When I add this into Xcode I get this:
Cannot invoke 'signUpInBackgroundWithBlock' with an argument list of type '((Bool!, NSError!) -> Void)'
When I run this code in Xcode 6.3 (non beta) it works fine. But in the Beta it fails and wont allow me to build. Any ideas if this will be cleared up or if there is a different implementation that I could use. Ive tried using just the signUpInBackgroundWithTarget but Im just not able to access the error correctly if one is received.
be sure you are using SDK version 1.7.1, then removing the types from your closure should do the trick:
user.signUpInBackgroundWithBlock { (succeeded, error) -> Void in
if error == nil {
println("success")
} else {
println("\(error)");
// Show the errorString somewhere and let the user try again.
}
}
Due to the new addition of "Nullability Annotations" to Swift 1.2, you have to rewrite the code above like this (using Parse 1.7.1+):
user.signUpInBackgroundWithBlock { (succeeded: Bool, error: NSError?) -> Void in
if let error = error {
println(error) // there is an error, print it
} else {
if succeeded {
println("success")
} else {
println("failed")
}
}
}
Parse is now returning optionals (?) instead of explicitely unwrapped objects (!).
Notation of Swift is changed
class AAPLList : NSObject, NSCoding, NSCopying {
// ...
func itemWithName(name: String!) -> AAPLListItem!
func indexOfItem(item: AAPLListItem!) -> Int
#NSCopying var name: String! { get set }
#NSCopying var allItems: [AnyObject]! { get }
// ...
}
After annotations:
class AAPLList : NSObject, NSCoding, NSCopying {
// ...
func itemWithName(name: String) -> AAPLListItem?
func indexOfItem(item: AAPLListItem) -> Int
#NSCopying var name: String? { get set }
#NSCopying var allItems: [AnyObject] { get }
// ...
}
So you can change
(succeeded: Bool!, error: NSError!) -> Void in
to
(success: Bool, error: NSError?) -> Void in
Which Parse SDK are you using? They released version 1.7.1 a few days ago that should fix your issue.
Change:
(succeeded: Bool!, error: NSError!) -> Void in
to
(succeeded, error) -> Void in
This change is required due to changes in the Parse SDK

Resources