【发布时间】:2018-04-19 22:00:31
【问题描述】:
我有这样的课:
struct myData {
let dataOne: String
let dataTwo: String
}
extension myData{
static func doSomeThingWithThis(someData:Any) -> String {
.
.
.
.
return str // is returning a string
}
init?(fromDict dict: [String: Any]) {
guard let dataOne = dict["someKey"] as? String else {
return nil
}
guard let dataTwo = myData.doSomeThingWithThis(someData: dict["anotherKey"]) else{
return nil
}
self.init(
dataOne: dataOne,
dataTwo: dataTwo,
)
}
但我在这一行的问题:
guard let dataTwo = myData.doSomeThingWithThis(someData: dict["anotherKey"]) else{
return nil
}
Xcode 具有以下错误/警告令人信服:
guard let dataTwo = myData.doSomeThingWithThis(someData: dict["anotherKey"]as? String) else{
return nil
}
或者这个:
guard let dataTwo = myData.doSomeThingWithThis(someData: dict["anotherKey"]as? String) else{
return nil
}
但 Xcode 仍然抱怨。你们中的任何人都知道如何解决此错误/警告?
非常感谢您的帮助。
【问题讨论】:
标签: ios initialization swift4 xcode9