Skip to content

Instantly share code, notes, and snippets.

@01GOD
Created January 15, 2015 21:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 01GOD/b82600609d65bea85555 to your computer and use it in GitHub Desktop.
Save 01GOD/b82600609d65bea85555 to your computer and use it in GitHub Desktop.
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 But it appears that only some of NSString's functions are accessible without explicitly bridging. To bridge to an NSString and use any of its functions, the following methods work: //Example Swift String var var newString:String = "this is a string" //Bridging to NSString //1 (newString as NSString).containsString("string") //2 newString.bridgeToObjectiveC().containsString("string") //3 NSString(string: newString).containsString("string") All three of these work. It's interesting to see that only some NSString methods are available to Strings and others need explicit bridging. This may be something that is built upon as Swift develops. share|improve this answer edited Jun 4 '14 at 3:08 answered Jun 3 '14 at 4:56 Jpoliachik 411313 add a comment up vote 2 down vote So what you actually have to do is this var str:NSString = "Checkcontains" str.containsString("ckc")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment