Cannot publish Facebook Open Graph Post in Swift - facebook

FBRequestConnection.startForPostOpenGraphObject(graphObject, {connection, result, error in
if(!error) {
var objectID : NSString = result.objectforKey("id")
println(objectID)
} else {
println(error.description)
}
})
I'm getting the following error on the expression:
Cannot convert the expression's type 'FBRequestConnection!' to 'Void'
I have looked all over SO but couldn't find a solution. Any ideas?
Help would be much appreciated. Thanks.

Maybe check your handler syntax. It should be something like:
let handler:FBRequestHandler = { (connection : FBRequestConnection!, result : AnyObject!, error : NSError!) -> Void in
if (error != nil) {
println(error)
} else {
println(result)
}
}
Myself, I'm struggling with getting FBOpenGraphObject from FBGraphObject.openGraphObjectForPost()

Related

Ambiguous Without More Context Error in Parse Query

I’m experimenting with Parse in a swift app and running through some of the examples but I can’t get the query to run. I’m getting the “ambiguous without more context” error in XCode. Here’s the code:
var query = PFQuery(className: "MyFirstClass")
query.getObjectInBackground(withId: "Jl0SUJWCQg") {
(myFirstClass: PFObject?, error: NSError?) -> Void in
if error == nil && myFirstClass != nil {
print(myFirstClass)
} else {
print(error)
}
}

Swift Error: cannot convert of type '()' to specified type 'Bool'

I am New for Swift and I Have Implement File Manager Concept in my Project but it shows the issue and I don't for how to solve this please any body help me for fix the issue.
Here I Post My Code.
class func addSkipBackupAttributeToItemAtPath(filePathString: String) throws -> Bool
{
let URL: NSURL = NSURL.fileURLWithPath(filePathString)
assert(NSFileManager.defaultManager().fileExistsAtPath(URL.path!))
let err: NSError? = nil
let success: Bool = try URL.setResourceValue(Int(true), forKey: NSURLIsExcludedFromBackupKey) //---- This Line Shows the Issue.
if !success {
NSLog("Error excluding %# from backup %#", URL.lastPathComponent!, err!)
}
return success
}
The benefit of the new error handling in Swift 2 is the omission of the quasi-redundant return values Bool / NSError. Therefore setResourceValue does not return a Bool anymore which is the reason of the error message.
As the function is marked as throws I recommend this syntax which just passes the result of setResourceValue
class func addSkipBackupAttributeToItemAtPath(filePathString: String) throws
{
let url = NSURL.fileURLWithPath(filePathString)
assert(NSFileManager.defaultManager().fileExistsAtPath(URL.path!))
try url.setResourceValue(true, forKey: NSURLIsExcludedFromBackupKey)
}
Handle the error in the method which calls addSkipBackupAttributeToItemAtPath
The method setResourceValue is a throw function and does not return a Bool.
Try running your function using a do-catch:
do {
try URL.setResourceValue(Int(true), forKey: NSURLIsExcludedFromBackupKey)
}
catch {
NSLog("Error excluding %# from backup %#", URL.lastPathComponent!, err!)
}

Swift Bridge and Closure Band SDK

I'm getting this error when trying to compile this code. Can someone help me debug?:
Cannot convert value of type '(NSError!) throws -> Void' to expected
argument type '((NSError!) -> Void)!'
Header:
#class MSBTile;
#protocol MSBTileManagerProtocol <NSObject>
- (void)addTile:(MSBTile *)tile completionHandler:(void(^)(NSError *error))completionHandler;
#end
ViewController:
client.tileManager.addTile(tile, completionHandler: {
(error: NSError!) -> Void in
if error == nil || MSBErrorType(rawValue: error.code) == MSBErrorType.TileAlreadyExist {
self.output("Creating page...")
...
})
} else {
self.output(error.localizedDescription)
}
})
I found a workaround for anyone who encounters this in the future. It turns out that two of the function calls were also throwables, so I had to wrap them in try catch blocks like so:
let pageTextBlock: AnyObject
do {
pageTextBlock = try MSBPageTextBlockData(elementId: 10, text: "TextButton Sample")
}catch _ {
pageTextBlock = ""
}
let pageButtonBlock: AnyObject
do {
pageButtonBlock = try MSBPageTextButtonData(elementId: 11, text: "Press Me")
}catch _ {
pageButtonBlock = ""
}
Disclaimer: I'm still new to Swift so this may not be the best solution.

Retrieve Data in Parse

I have searched through a number of similar topics but have not found a solution as of yet. I am using Parse social and using the login files.
I get the following error:
"AnyObject?" is not convertible to 'String'
I am very new to Swift & Parse - I believe this is the correct method of retrieving data, so please correct me if I am wrong.
var userObjectID = PFUser.currentUser()!.objectId!
var query = PFQuery(className:"User")
query.getObjectInBackgroundWithId("\(userObjectID)") {
(userInfo: PFObject?, error: NSError?) -> Void in
if error == nil && userInfo != nil {
println(userInfo)
let userScore = userInfo["level"] as! String
} else {
println(error)
}
}
Below is the database on Parse
I think you need to unwrap the PFObject you receive:
let userScore = userInfo!["level"] as! String

Stripe error "create token with card(_:completion:) is unavailable"

In this line, the error was Display. Can someone tell me what mistake was made?
Stripe.createTokenWithCard(card, completion: { (token: STPToken!, error: NSError!) -> Void in
self.handleToken(token)
I had the same problem after updating Stripe in pods recently. That method is deprecated. Instead, you can use the following code:
STPAPIClient.sharedClient().createTokenWithCard(card, completion: { (token: STPToken!, error: NSError!) -> Void in
})
It takes the same parameters.
Update
Thanks to #Christine and #Keyhole150
This function in Stripe API has now be changed to
STPAPIClient.sharedClient().createTokenWithCard(card, completion: { (token: STPToken?, error: NSError?) -> Void in
})
Thanks, #Shali! Your tip is helpful.
For those who are beginners like me, you might still get an error. In case you experience an error indicating either an extra argument in call before adding sharedClient() or how createTokenWithCard cannot be invoked after sharedClient() is added, it helps to make the completion arguments optional (as in STPToken? and NSError?).
As mentioned by Christine, the method now uses Optionals so it looks like the following:
STPAPIClient.sharedClient().createTokenWithCard(card, completion: { (token: STPToken?, error: NSError?) -> Void in
})
For objective-c using latest stripe pod
#import "Stripe.h"
STPCardParams *cardParams = [[STPCardParams alloc] init];
cardParams.number = #"4242424242424242";
cardParams.expMonth = 10;
cardParams.expYear = 2018;
cardParams.cvc = #"123";
[[STPAPIClient sharedClient] createTokenWithCard:cardParams completion:^(STPToken *token, NSError *error) {
if (token == nil || error != nil) {
// Present error to user...
NSLog(#"%#",error.description);
return;
}
NSLog(#"token.tokenId :: %#",token.tokenId);
}];