Skip to content

Instantly share code, notes, and snippets.

@lukaskollmer
Created May 12, 2016 18:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukaskollmer/1e0587599ab4d40f59299d72870f22b1 to your computer and use it in GitHub Desktop.
Save lukaskollmer/1e0587599ab4d40f59299d72870f22b1 to your computer and use it in GitHub Desktop.
Import ObjC frameworks
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