-1

I am creating username from first and last name. It was working fine with swift 2.2 but after migrating to swift 3 now the string do get concate but when it does the first name is have optional with it. Check below images enter image description here

enter image description here

enter image description here

Parth Adroja
  • 13,198
  • 5
  • 37
  • 71

1 Answers1

2

use like this

let name = "\(firstName!) \(lastName)"

I have tried with basic example too. If string contain optional("") then you can resolve it by this by force the compiler to implicitly force unwrap.

you can check in .playground

let firstname : String!
let lastname : String!
firstname = "Hello" ==> "Hello"
lastname = "World" ==> "World"

let fullname = "\(firstname) \(lastname)" ==> "Optional("Hello") Optional("World")"

let fullname = "\(firstname!) \(lastname!)" ==> "Hello World"

Give it a try using above solution, Hope it Helps!

Wolverine
  • 4,264
  • 1
  • 27
  • 49