Reputation: 1576
I tried to call a objective-c method out of swift and am getting this weird error:
Cannot convert the expression's type 'Void' to type 'String!'
Swift code:
XNGAPIClient.sharedClient().putUpdateGeoLocationForUserID("me",
accuracy: 3000,
latitude: location.coordinate.latitude as CGFloat,
longitude: location.coordinate.longitude as CGFloat,
ttl: 420, success: { (JSON: AnyObject!) in },
failure: { (error: NSError!) in })
Objective-C method:
- (void)putUpdateGeoLocationForUserID:(NSString*)userID
accuracy:(CGFloat)accuracy
latitude:(CGFloat)latitude
longitude:(CGFloat)longitude
ttl:(NSUInteger)ttl
success:(void (^)(id JSON))success
failure:(void (^)(NSError *error))failure
If I convert everything to the suggested types:
XNGAPIClient.sharedClient().putUpdateGeoLocationForUserID("me" as String,
accuracy: 3000 as CGFloat,
latitude: location.coordinate.latitude as CGFloat,
longitude: location.coordinate.longitude as CGFloat,
ttl: 420 as Int,
success: { (JSON: AnyObject!) in },
failure: { (error: NSError!) in })
I get the following error: Cannot convert the expression's type 'Void' to type 'StringLiteralConvertible'
Upvotes: 4
Views: 2676
Reputation: 38238
Your problem is the location.coordinate.latitude
and location.coordinate.longitude
parameters. I can reproduce your problem if I make those parameters Int, for example. So, try:
XNGAPIClient.sharedClient().putUpdateGeoLocationForUserID("me" as String,
accuracy: 3000 as CGFloat,
latitude: CGFloat(location.coordinate.latitude),
longitude: CGFloat(location.coordinate.longitude),
ttl: 420 as Int,
success: { (JSON: AnyObject!) in },
failure: { (error: NSError!) in })
...that is, using the CGFloat constructor rather than the down casting as
for those parameters. (I'd take a guess that there's something clever going on behind the scenes for the 3000 literal that looks like it should be an Int, otherwise that one probably wouldn't work, either...)
I'd also raise a bug with Apple for the very unhelpful error message. I've seen a few of those from calls to Objective C with the wrong parameter types.
Upvotes: 2