Last active
          August 29, 2015 14:14 
        
      - 
      
- 
        Save morizotter/bf6a188600d3b9ed9c17 to your computer and use it in GitHub Desktop. 
    SwiftでMethod Swizzling ref: http://qiita.com/morizotter/items/a6dffb547675e9184326
  
        
  
    
      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
    
  
  
    
  | func swizzle() { | |
| var dict = ["This is Key.": "This is value."] as NSDictionary | |
| var method: Method = class_getInstanceMethod(object_getClass(dict), "description") | |
| var swizzledMethod: Method = class_getInstanceMethod(object_getClass(dict), "myDescription") | |
| method_exchangeImplementations(method, swizzledMethod) | |
| println(dict.description) | |
| } | 
  
    
      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
    
  
  
    
  | MY DESCRIPTION!! | |
| { | |
| "This is Key." = "This is value."; | |
| } | 
  
    
      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
    
  
  
    
  | extension NSDictionary { | |
| func myDescription() -> String { | |
| println("MY DESCRIPTION!!") | |
| return myDescription() | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment