简体   繁体   中英

Type 'AnyObject' does not conform to protocol 'BooleanType'

this is my code in objective c

 id locationValue = [launchOptions objectForKey:UIApplicationLaunchOptionsLocationKey];
if (locationValue)
{
    UIApplication *app  = [UIApplication sharedApplication];
    UIBackgroundTaskIdentifier bgTask = UIBackgroundTaskInvalid;
    bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
        [app endBackgroundTask:bgTask];
    }];
    [self startLocationUpdates];
}

i define locationValue as AnyObjectType and the error mentioned as the title hits at the line

if(locationValue)

I am converting this to swift .. so please help..

The value of any condition in an if statement must have a type that conforms to the BooleanType protocol, which means that the condition must be a boolean expression.

locationValue is not a boolean expression, you want if(locationValue != nil) .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM