3

Prior to the new Swift version I was using the following code in my app. Now it launches an exception.

for (i, in 0 ..< len){ let length = UInt32 (letters.length) let rand = arc4random_uniform(length) randomString.appendFormat("%C", letters.characterAtIndex(Int(rand))) } 

XCode says:

  • Expected pattern
  • Expected "," separator
  • Expected "in" after for-each pattern
  • Expected SequenceType expression for for-each loop

Changing the code with the proposed solutions doesn't change the exceptions thrown.

Any help is welcome to update the code to the current Swift version.

2
  • you are converting in swift 2.2 right ? Commented Mar 27, 2016 at 5:47
  • @Pyro, I uploaded the app last week and it was working fine. I guess that after the new update on 21st march to version 2.2, some part of my code has been deprecated. Commented Mar 27, 2016 at 5:49

2 Answers 2

4

For for syntax you are using have been deprecated, and should be changed to

for _ in 0..<len // rest of your code 
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you Claus, let me check your proposal.
2

the question already has correct answer still i have converted it so posting here may be some get help from it

let len = 5 let letters:NSString = "str" for i in 0 ..< len { let length = UInt32 (letters.length) let rand = arc4random_uniform(length) let randomString:NSMutableString = "" randomString.appendFormat("%C", letters.characterAtIndex(Int(rand))) } 

As some of the variable are not shown in the code i have made them based on the parameters

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.