 
 let basicRect = Rect()
 
+var basic = basicRect
+
 class Food{
     var name: String
     init(name: String){

let oneMysteryItem = RecipeIngredient()
let oneBacon = RecipeIngredient(name: "Bacon")
let sixEggs = RecipeIngredient(name: "Eggs", quantity: 6)

class ShoppingListItem: RecipeIngredient {
    var purchased = false

}


struct Animal{
    let species: String
    init?(species: String){
        if species.isEmpty {
            return nil
        }
        self.species = species
    }
}

let someCreature = Animal(species: "Giraffe")
if let giraffe = someCreature{
    print("An animal was initialized with a species of \(giraffe.species)")
}

let nilCreature = Animal(species: "")

func guardTest(){
    guard nilCreature != nil else{
        print("nilCreature = \(nilCreature)")
        return
    }
}

guardTest()


enum TemperatureUnit{
    case Kelvin, Celsius, Fahrenheit
    
    init?(symbol: Character){
        switch symbol {
        case "K":
            self = .Kelvin
        case "C":
            self = .Celsius
        case "F":
            self = .Fahrenheit
        default:
            return nil
        }
    }
}

let fahrenheitUnit = TemperatureUnit(symbol: "F")
if fahrenheitUnit != nil{
    print("This is a defined temperature unit, so initialization succeeded.")
}

let unknownUnit = TemperatureUnit(symbol: "X")
if unknownUnit == nil{
    print("This is not a defined temperature unit, so initialization failed.")
}


class Product{
    let name: String
    init?(name: String){
        if name.isEmpty{ return nil }
        self.name = name
    }
}

class CartItem: Product{
    let quantity: Int
    init?(name: String, quantity:Int) {
        if quantity < 1 { return nil }
        self.quantity = quantity
        super.init(name: name)
    }
}

if let twoSocks = CartItem(name: "sock", quantity: 4){
    print("Item: \(twoSocks.name), quantity: \(twoSocks.quantity)")
}

class Document{
    var name: String?
    init(){}
    init?(name: String){
        if name.isEmpty{ return nil }
        self.name = name
    }
}

class AutomaticallyNameDocument: Document{
    override init(){
        super.init()
        self.name = "[Untitled]"
    }
    
    override init(name: String) {
        super.init()
        if name.isEmpty {
            self.name = "[Untitled]"
        }else{
            self.name = name
        }
    }
}

class SomeClassClosure{
    var someProperty: String = "" {
        willSet{
            print("willSet")
        }
        
        didSet{
            someProperty = "test"
        }
    }
    
    let some: Int = {
        return 33
    }()
}


























