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 trialJavid Beykzadeh
5,863 PointsExpected Declaration
On var tshirt = Clothing(title: "Vintage", price: 49.99) I'm getting error Enum may not contain stored procedure and on and same error on let quadcopter = Product(title: "Quadcopter", price: 499.99). On tshirt.title I am getting Expected Declaration. My code is entered just like Amit's. Anyone know what is going on?
// Method Overriding
import UIKit
//struct does not need an initializer, one is provided by default
//stored properties, constants or variables
/*quadcopter.price = 199.99*/
class Product { //base class and super class of clothing
let title: String
var price: Double = 0.0 //Xcode made me change to Var from let
init(title: String, price: Double) {
self.title = title
self.price = price
}
func discountedPrice(percentage: Double) -> Double {
return price - (price * percentage / 100)
}
}
enum Size {
case Small, Medium, Large
init () {
self = .Small
}
class Clothing: Product { //subclass
var size = Size()
override func discountedPrice(percentage: Double = 10.0) -> Double {
return price - (price * percentage / 100)
}
}
var tshirt = Clothing(title: "Vintage", price: 49.99)
tshirt.title
tshirt.price
tshirt.discountedPrice(50)
tshirt.size
let quadcopter = Product(title: "Quadcopter", price: 499.99)
1 Answer
Jhoan Arango
14,575 PointsHello Javid:
Your code is Ok, the only problem that I see, is that it's missing the closing curly bracket on your enum. Once you add that, problem solved.
enum Size {
case Small, Medium, Large
init () {
self = .Small
}
} // This curly bracket one is MIA in your code.
// MIA = Missing In Action :-| lol
Happy Coding. Good luck.