Avatar ·

How to check if a string contains another string in Swift?

Hello everyone! I'm new to Swift, transitioning from Objective-C, and I can't figure out working with strings. In Objective-C I used `rangeOfString:` to check for substring occurrence, for example: ```objc NSString *string = @"hello Swift"; if ([string rangeOfString:@"Swift"].location != NSNotFound) { NSLog(@"String contains 'Swift'"); } ``` But in Swift I see that strings are structs, not objects, and they don't have a `rangeOfString` method. I tried using `containsString`, but the compiler complains that there is no such method. I wrote this code: ```swift let string = "hello Swift" if string.containsString("Swift") { print("String contains 'Swift'") } ``` I get an error: `Value of type 'String' has no member 'containsString'`. I googled it, and they say that in Swift 3 and above