Created
October 17, 2015 23:12
-
-
Save takaheraw/801fb91526b1ecda56b8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Product : NSObject, NSCopying { | |
private(set) var name:String | |
private var stockLevelBackingValue:Int = 0 | |
init(name:String, stockLevel:Int) { | |
self.name = name | |
super.init() | |
self.stockLevel = stockLevel | |
} | |
var stockLevel:Int { | |
get { | |
return stockLevelBackingValue | |
} | |
set { | |
stockLevelBackingValue = max(0, newValue) | |
} | |
} | |
func copyWithZone(zone: NSZone) -> AnyObject { | |
return Product(name: self.name, stockLevel: self.stockLevel) | |
} | |
} | |
var handler = { (p:Product) in | |
print("Change: \(p.name) \(p.stockLevel) items in stock") | |
} | |
let logger = Logger<Product>(callback: handler) | |
logger.logItem(Product(name: "Kayak", stockLevel: 10)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment