They are interchangeable, so there's really no reason not to use NSString and its constructors when you need to. This will work fine:
var datastring: String = NSString(data:data, encoding:NSUTF8StringEncoding)
There's no type mismatch error here because Swift recognises the return type of NSString's constructor as matching the specified String type of datastring. You can then use datastring just like any other Swift string, e.g.
var foo = datastring + "some other string"
swift NSData NSString
原创
©著作权归作者所有:来自51CTO博客作者lisiben的原创作品,请联系作者获取转载授权,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章