In Objective-C
the code to check for a substring in an NSString
is:
NSString *string = @\"hello Swift\";
NSRange textRange =[strin
You can just do what you have mentioned:
import Foundation
...
string.contains("Swift");
From the docs:
Swift’s
String
type is bridged seamlessly to Foundation’sNSString
class. If you are working with the Foundation framework in Cocoa or Cocoa Touch, the entireNSString
API is available to call on anyString
value you create, in addition to the String features described in this chapter. You can also use a String value with any API that requires an NSString instance.
You need to import Foundation
to bridge the NSString
methods and make them available to Swift's String class.