I have the following code:
twitterAPI?.verifyCredentialsWithUserSuccessBlock({ (userName, password) -> Void in
twitterAPI?.getUserTimelineWithScreenName(userName, count: 100, successBlock: { ([AnyObject]!) -> Void in
}, errorBlock: { (error :NSError!) -> Void in
})
}, errorBlock: { (error :NSError!) -> Void in
println("error block")
})
I am getting the following errors:
I tried saying self inside the outer closure but it did not work. What am I missing?
UPDATED: Still having build errors:
UPDATE: If I put the getUserTimeline method outside the closure then it works. THIS ONE WORKS.
// twitterAPI?.getUserTimelineWithScreenName("", successBlock: { (objects :[AnyObject]!) -> Void in
//
// }, errorBlock: { (error: NSError!) -> Void in
//
// })
But this DOES NOT:
twitterAPI?.verifyCredentialsWithUserSuccessBlock({ (userName, password) -> Void in
self.twitterAPI?.getUserTimelineWithScreenName("", successBlock: { (objects :[AnyObject]!) -> Void in
}, errorBlock: { (error: NSError!) -> Void in
})
}, errorBlock: { (error :NSError!) -> Void in
})
UPDATE: Definition of getUserTimeLine method
self.twitterAPI?.getUserTimelineWithScreenName(<#screenName: String!#>, successBlock: <#(([AnyObject]!) -> Void)!##([AnyObject]!) -> Void#>, errorBlock: <#((NSError!) -> Void)!##(NSError!) -> Void#>)
UPDATE: Now, I am getting a build error saying missing argument sinceID. I am not even using that constructor.
if let twitterAPI = self.twitterAPI {
twitterAPI.verifyCredentialsWithUserSuccessBlock({ (userName, password) -> Void in
twitterAPI.getUserTimelineWithScreenName(userName, successBlock: { (objects :[AnyObject]!) -> Void in
}, errorBlock: { (error :NSError!) -> Void in
})
}, errorBlock: { (error :NSError!) -> Void in
})
}
Try:
twitterAPI?.verifyCredentialsWithUserSuccessBlock({ (userName, password) -> Void in
self.twitterAPI?.getUserTimelineWithScreenName(userName, successBlock: { (objects :[AnyObject]!) -> Void in
}, errorBlock: { (error :NSError!) -> Void in
})
return // <-- ADDED
}, errorBlock: { (error :NSError!) -> Void in
})
In this case
{ (userName, password) -> Void in
self.twitterAPI?.getUserTimelineWithScreenName("", successBlock: { (objects :[AnyObject]!) -> Void in
}, errorBlock: { (error: NSError!) -> Void in
})
}
is a "single expression closure" that has implicit non Void
return.
As of Xcode 6.2 / Swift 1.1, you need explicit return
here.
Or, use Xcode 6.3 / Swift 1.2 that has fixed this problem.
See this question: One-line closure without return type or Swift - 'Bool' is not a subtype of 'Void'?
Ok, by the method names you are using, I'm guessing you are using the STTwitter library. If that's the case, you'll want something like this:
if let twitterAPI = self.twitterAPI {
twitterAPI.verifyCredentialsWithSuccessBlock({ (String) -> Void in
twitterAPI.getUserTimelineWithScreenName("test", successBlock: { (objects: [AnyObject]!) -> Void in
println("success")
}, errorBlock: { (error: NSError!) -> Void in
println("failure")
})
}, errorBlock: { (error: NSError!) -> Void in
})
}
Note the let call before using the optional self.twitterAPI
variable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With