简体   繁体   中英

Cast from 'TCHMessageType' to unrelated type 'String' always fails

I am using Twilio Chat Client SDK for iOS where I am getting this warning. How can I get rid of this warning in my XCode?

messageAdded message: TCHMessage
let msgType: String = message.messageType as! String

Twilio DOC: https://media.twiliocdn.com/sdk/ios/chat/releases/3.1.1/docs/Constants/TCHMessageType.html

Warning: Cast from 'TCHMessageType' to unrelated type 'NSString' always fails

Since this is just a warning not an error and my code compiles and run great but I don't want to push code with warnings to the production level.

Any help?

message.messageType is of type TCHMessageType which is an enum. Maybe you want to use message.messageType.text , which is an Int. If you want to save it as string, just change it to

let msgType: String = "\(message.messageType.text)"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM