Search code examples
swiftmodelswift4word-wrap

How to handle this: Swift.ImplicitlyUnwrappedOptional<Swift.String>.some


Since Xcode 9.3 I get my string variables in my models wrapped with "Swift.ImplicitlyUnwrappedOptional.some"

I don't know how this is happening but its ruined my apps!

I create my models like this:

struct MyModel {
  var myString:String!
  init(){} // for creating empty instances.
  init(son:JSON){
     myString = son["theStringKey"].string
  }
}

Till Xcode 9.3 when I printed my model I got pure string variable from it.

But after Xcode 9.3 it gives me wrapped string inside of Swift.ImplicitlyUnwrappedOptional.some("MyStringValue")

Any Idea what is this?


Solution

  • Today i have facing same error in Xcode 9.3 V

    Just add option value ?? "" your problem is solved

      let paramData:Dictionary<String,Any> = [ PARAM.REQUEST_ID : requestId ?? ""]
    

    Here you can pass json replace in dictionary

    struct MyModel {
        var myString:String!
        init(){} // for creating empty instances.
        init(son:Dictionary<String,Any>){
            myString = son["theStringKey"] as! String
        }
    }
    print(MyModel.init(son: ["theStringKey":"Harshil"]).myString ?? "")