Cannot convert expression type to Void to enter String!

I tried calling the objective-c method from swift and got this strange error:

Cannot convert the expression type 'Void' to type 'String!'

Quick 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 type 'Void' to type 'StringLiteralConvertible'

+4
source share
1 answer

Your problem is with the parameters location.coordinate.latitudeand location.coordinate.longitude. I can reproduce your problem if I make these Int parameters, 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 })

... , CGFloat, as . ( , - 3000- , , Int, , , ...)

Apple . Objective C .

+2

Source: https://habr.com/ru/post/1545623/


All Articles