4

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?

Ahmadreza
  • 6,950
  • 5
  • 50
  • 69

1 Answers1

2

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 ?? "")
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Harshil Kotecha
  • 2,846
  • 4
  • 27
  • 41