Skip to content

Instantly share code, notes, and snippets.

@nolili
Created July 6, 2014 15:30
Show Gist options
  • Save nolili/47d828206a62fc9f0427 to your computer and use it in GitHub Desktop.
Save nolili/47d828206a62fc9f0427 to your computer and use it in GitHub Desktop.
// 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