Skip to content

Instantly share code, notes, and snippets.

@smugen
Last active August 29, 2015 14:17
Show Gist options
  • Save smugen/3d7af6992d7f34513e87 to your computer and use it in GitHub Desktop.
Save smugen/3d7af6992d7f34513e87 to your computer and use it in GitHub Desktop.
Swift 1.2 notes
class ClassName : NSObject {
static var i = 0
// static / class function (seems the same)
static func fn() {}
class func fn2() {}
init() {}
// helper for access static member in instance func
private var Class : ClassName.Type {
get {
return self.classForCoder as! ClassName.Type
}
}
func ifn() {
Class.fn()
Class.fn2()
Class.i
}
}
// call init return instance
let instance = ClassName()
// class itself
let classItself = ClassName.self
// call init return instance
let instance2 = classItself.init()
// get class itself from instance
let cls = instance.classForCoder as! ClassName.Type
class Singleton : NSObject {
static let sharedInstance = Singleton()
// mark as private to prevent be called directly
private override init() {
println("\(__FUNCTION__)")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment