Created
          May 12, 2016 18:41 
        
      - 
      
- 
        Save lukaskollmer/1e0587599ab4d40f59299d72870f22b1 to your computer and use it in GitHub Desktop. 
    Import ObjC frameworks
  
        
  
    
      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
    
  
  
    
  | from objc_util import * | |
| class ImportFrameworkError(Exception): | |
| def __init__(self, name): | |
| self.name = name | |
| def __str__(self): | |
| return 'Couldn\'t import {}.framewrork. (Neither from public, nor from private frameworks)'.format(self.name) | |
| def _framework_path(name, private): | |
| return '/System/Library/{}Frameworks/{}.framework'.format('Private' if private else '', name) | |
| def importFramework(name): | |
| global _framework_path # This is required to work when the import stuff is importes in the startup file | |
| public_path = _framework_path(name, private=False) | |
| private_path = _framework_path(name, private=True) | |
| bundle = NSBundle.bundleWithPath_(public_path) | |
| if not bundle is None: | |
| bundle.load() | |
| else: | |
| # Could not load public bundle, will try private | |
| bundle = NSBundle.bundleWithPath_(private_path) | |
| if not bundle is None: | |
| bundle.load() | |
| else: | |
| raise ImportFrameworkError(name) | |
| if __name__ == '__main__': | |
| importFramework('UIKit') | |
| importFramework('') | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment