Xcode 8 Beta 6: storeViewController.loadProduct - ios

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
})

Related

error in printing in iOS 10

I have a project that I am converting to swift 3. In my printing code, which has been working in swift 2.3 and iOS 9, I have the following lines:
func completionFunc(_: UIPrintInteractionController, _: Bool, _: NSError? ){
// some action
}
DispatchQueue.main.async{
printController.present( animated: true, completionHandler: completionFunc )
}
now I am getting the following error:
error: cannot convert value of type '(UIPrintInteractionController, Bool, NSError?) -> ()' to expected argument type 'UIPrintInteractionCompletionHandler?'
printController.present( animated: true, completionHandler: completionFunc )
^~~~~~~~~~~~~~
From the documentation the definition of UIPrintInteractionCompletionHandler is:
typealias UIPrintInteractionCompletionHandler = (UIPrintInteractionController, Bool, Error?) -> Void
so I can not understand the error that has just appeared when trying to migrate the code to swift 3.
Thanks
Reza

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.

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

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)
}

How do I use a completionBlock in swift?

I'm trying to utilize swift's SKStoreProductViewController, but am getting errors with my syntax, specifically with my completion block.
Here is my code:
let storeViewController:SKStoreProductViewController = SKStoreProductViewController();
storeViewController.delegate = self;
var productparameters = [SKStoreProductParameterITunesItemIdentifier:someitunesid];
storeViewController.loadProductWithParameters(productparameters,
(success: Bool!, error: NSError!) -> Void in
if success {
self.presentViewController(storeViewController, animated: true, completion: nil);
} else {
NSLog("%#", error)
}
)
After running this I get an expected "," separator error between the error:NSError!),-> Void
This doesn't make sense to me as the apple docs call for:
func loadProductWithParameters(_ parameters: [NSObject : AnyObject]!,
completionBlock block: ((Bool, NSError!) -> Void)!)
What am I doing wrong?
You're 99% there, you just need braces around your block to have the correct closure syntax:
storeViewController.loadProductWithParameters(productparameters, { (success: Bool!, error: NSError!) -> Void in
if success {
self.presentViewController(storeViewController, animated: true, completion: nil);
} else {
NSLog("%#", error)
}
})
You can read more about closures in Apple's documentation.

Resources