简体   繁体   English

类型“ AnyObject”不符合协议“ BooleanType”

[英]Type 'AnyObject' does not conform to protocol 'BooleanType'

this is my code in objective c 这是我在目标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 我将locationValue定义为AnyObjectType,并在标题符合该行时提到错误

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. if语句中任何条件的值都必须具有符合BooleanType协议的类型,这意味着条件必须是布尔表达式。

locationValue is not a boolean expression, you want if(locationValue != nil) . locationValue不是布尔表达式,你想要if(locationValue != nil)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 类型“NSPersistentStore”在swift中不符合协议“BooleanType” - Type 'NSPersistentStore' does not conform to protocol 'BooleanType' in swift 类型“T”不符合协议“AnyObject” - Type 'T' does not conform to protocol 'AnyObject' 类型'AnyObject'不符合协议'NSFetchRequestResult' - Type 'AnyObject' does not conform to protocol 'NSFetchRequestResult' 类型[String:String]不符合协议“ AnyObject” - type [String: String] does not conform to protocol 'AnyObject' 类型&#39;AnyObject&#39;不符合协议&#39;Hashable&#39; - Type 'AnyObject' does not conform to protocol 'Hashable' 输入&#39;[NSObject:AnyObject]!&#39; 不符合协议&#39;DictionaryLiteralConvertible&#39; - Type '[NSObject : AnyObject]!' does not conform to protocol 'DictionaryLiteralConvertible' 类型MCSessionState不符合协议“ AnyObject” - Type MCSessionState does not conform to protocol 'AnyObject' 类型“ AnyObject”不符合协议“ sequenceType” - Type 'AnyObject' does not conform protocol 'sequenceType' 游乐场执行失败: <EXPR> :15:33:错误:类型&#39;Int&#39;不符合协议&#39;BooleanType&#39; - Playground execution failed: <EXPR>:15:33: error: type 'Int' does not conform to protocol 'BooleanType' 类型&#39;Int32&#39;不符合协议&#39;AnyObject&#39;Swift? - Type 'Int32' does not conform to protocol 'AnyObject' Swift?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM