I got error on xcode7.3 when I tried to convert my codes from xcode7.2

60 Views Asked by At

I got error when I converted my codes from xcode7.2 to 7.3. The error I get says that cannot convert value of type 'NSString' to expected argument type 'String!'Does anyone know how to fix this? I really need your help.

let text = snapshot.value["text"] as? NSString
            let sender = snapshot.value["from"] as? NSString
            let name = snapshot.value["name"] as? NSString

            var isOutGoing:Bool

            if sender == GetUserId(){
                isOutGoing = true
            }else{
                isOutGoing = false
            }

            let mediaItem = self.createPhotoItem(Const.S3_URL + (text! as String), isOutgoing: isOutGoing)

            var message:JSQMessage
            if text!.hasSuffix(".jpg"){
                message = JSQMessage(senderId: sender, displayName: name, media: mediaItem)

            }else{
                message = JSQMessage(senderId: sender, displayName: name, text: text)
            }
1

There are 1 best solutions below

4
On

Just create a new String form the NSString:

let regularString = myNSString as String

So you would use

displayName: name as String