Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialMax Howarth
2,605 Points"var parameters are depreciated and will be removed in Swift 3" - how does this change our example?
In this example, we use a var parameter player of type "PlayerType" in the attack func.
I am getting an error saying that var parameters will be depreciated in Swift 3, and they recommend removing the "var" from the function, but doing so creates an error as they say "player is a let-type".
How would we accomplish the same function without using a var parameter?
class Enemy: PlayerType, Destructable , Attackable, Movable {
var position: Point
var life: Int = 10
var strength: Int = 5
var range: Int = 2
required init(point: Point) {
self.position = point
}
func decreaseLife(factor: Int) {
self.life -= factor
}
func attack(var player: PlayerType) {
player.life = player.life - strength
}
func move(direction: Direction, distance: Int) {
switch direction {
case .Up: position.y += 1
case .Down: position.y -= 1
case .Left: position.x -= 1
case .Right: position.x += 1
}
}
}
2 Answers
Stone Preston
42,016 Pointsyou could try something like this:
func attack(player: PlayerType) {
var player = player
player.life = player.life - strength
}
I cant test anything right now but just going by what the stack overflow comments show, that might work
Dalisson Figueiredo
7,731 PointsThat is because the syntax will change on following updates of swift, so get used to the code the moderator has provided: func attack(player: PlayerType) { var player = player player.life = player.life - strength }