Reputation: 40
static func randomShape() -> Shape {
// Find out count of possible shapes
var maxValue = 0
while let _ = self.init(rawValue: ++maxValue) {}
// Generate random number from number of shapes
let randomNumber = Int(arc4random_uniform(UInt32(maxValue)))
// Create and return shape
let shape = self.init(rawValue: randomNumber)!
return shape
}
Focus on the while let _ = self.init(rawValue: ++maxValue) {}
I et the Error that ++
has been deprecated from Swift, However I don't know how i can change my method to still function right.
I tried MaxValue += 1 and i get the error
'+=' produces '()', not the expected contextual result type 'Int'
Your help is much appreciated!
Upvotes: 0
Views: 4499
Reputation: 8463
@Chris Karani you can use Xcode to fix this kind of issues. Try to use Xcode's red error dots at left of your editor. For instance :
if you will click on "fix-it" it'll handle all for you.
Also you can use "Edit/Convert/To Current Swift Syntax" menu for converting all your project to Swift 3 syntax. Make sure you select your main target from "Select targets to convert" screen.
Your answer is :
maxValue += 1
Upvotes: 3
Reputation: 77631
++value
Basically increments the value first and then uses the new value.
So this...
someFunc(++value)
Is the same as doing...
value += 1
someFunc(value)
Upvotes: 7