我吃疯狂药吗直接从文档中删除:
“Swift automatically bridges between the String type and the Nsstring class. This means that anywhere you use an Nsstring object,you can use a Swift String type instead and gain the benefits of both types—the String type’s interpolation and Swift-designed APIs and the Nsstring class’s broad functionality. For this reason,you should almost never need to use the Nsstring class directly in your own code. In fact,when Swift imports Objective-C APIs,it replaces all of the Nsstring types with String types. When your Objective-C code uses a Swift class,the importer replaces all of the String types with Nsstring in imported API.
要启用字符串桥接,只需导入基础“.
我做了这个…考虑:
import Foundation var str = "Hello World" var range = str.rangeOfString("e") // returns error: String does not contain member named: rangeOfString()
然而:
var str = "Hello World" as Nsstring var range = str.rangeOfString("e") // returns correct (2,1)
我错过了什么吗?