Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

replacingOccurrences error

From udacity course I am trying below code

 let password = "Meet me in St. Louis"
 let newPassword = password.replacingOccurrences(of: "e", with: "3")

This is giving

Playground execution failed: Introduction.xcplaygroundpage:31:19: error: value of type 'String' has no member 'replacingOccurrences'
let newPassword = password.replacingOccurrences(of: "e", with: "3")
              ^~~~~~~~ ~~~~~~~~~~~~~~~~~~~~

Forcefully I have to use

let password = "Meet me in St. Louis"
let newPassword = password.stringByReplacingOccurrencesOfString("me", withString: "ss")

Any clue why this error coming? I am using swift version 2.2

like image 598
R World Avatar asked Oct 27 '25 22:10

R World


1 Answers

In case you run this code example from the command line (by running Swift REPL), add import Foundation at the beginning of your .swift file.

like image 129
Dmitry Sobolev Avatar answered Oct 29 '25 12:10

Dmitry Sobolev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!