Created
July 6, 2014 15:30
-
-
Save nolili/47d828206a62fc9f0427 to your computer and use it in GitHub Desktop.
This file contains 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
// Playground - noun: a place where people can play | |
import UIKit | |
var str = "Hello, playground" | |
class Counter:NSObject, NSCopying{ | |
var count = 0; | |
func add(){ | |
count++ | |
} | |
func sub(){ | |
if (count > 0){ | |
count-- | |
} | |
} | |
func reset(){ | |
count = 0 | |
} | |
// NSCopying | |
func copyWithZone(zone: NSZone) -> AnyObject! { | |
var newInstance = Counter() | |
newInstance.count = self.count | |
return newInstance} | |
} | |
let counter = Counter() | |
counter.add() | |
counter.sub() | |
counter.sub() | |
counter.add() | |
counter.add() | |
counter.reset() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment