0

The answer in this question: How do I check if a string contains another string in Swift?

No longer works.

var string = "hello Swift"

if string.rangeOfString("Swift") != nil{
    println("exists")
}

Will get you:

error: value of type 'String' has no member 'rangeOfString'

What is the new way to do this?

5
  • Seems to me that you are using Swift 1.2 not 2.1. Just update your Xcode to the latest version itunes.apple.com/us/app/xcode/id497799835?mt=12 Commented Oct 17, 2015 at 2:54
  • println it is not Xcode 7.0.1 Commented Oct 17, 2015 at 2:57
  • The code snippet is to indicate the old answer no longer works, plus you will reach an error before println ever executes Commented Oct 17, 2015 at 2:59
  • 1
    the code works fine for me here Xcode 7.0.1. Exempt println() :) Commented Oct 17, 2015 at 3:00
  • The accepted answer to the linked question explicitly mentions: "PS. Don't forget to import Foundation". Commented Oct 17, 2015 at 7:48

1 Answer 1

5

Import Foundation and you will be able to call rangeOfString.

Sign up to request clarification or add additional context in comments.

1 Comment

indeed I was working in Playground, and could not get the rangeOfString method to work initially, but after I imported Foundation all went smooth.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.