Last active
          August 29, 2015 14:17 
        
      - 
      
 - 
        
Save smugen/3d7af6992d7f34513e87 to your computer and use it in GitHub Desktop.  
    Swift 1.2 notes
  
        
  
    
      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 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 | 
  
    
      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 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