"""
Utilities for the pythonista package
"""

__author__ = "Lukas Kollmer<lukas.kollmer@gmail.com>"
__copyright__ = "Copyright (c) 2016 Lukas Kollmer<lukas.kollmer@gmail.com>"


try:
	import objc_util
	_HAS_OBJC_UTIL = True
except:
	_HAS_OBJC_UTIL = False

_application = objc_util.UIApplication.sharedApplication()

def guard_objc_util():
	if not _HAS_OBJC_UTIL: raise NameError("objc_util not available")

def add_method(method, cls):
	guard_objc_util()
	import ctypes
	import objc_util
	import uuid
	
	encoding = "v@:"
	
	# this code is borrowed from `objc_util._add_method`
	parsed_types = objc_util.parse_types(encoding)
	restype = parsed_types[0]
	argtypes = parsed_types[1]
	IMPTYPE = ctypes.CFUNCTYPE(restype, *argtypes)
	imp = IMPTYPE(method)
	objc_util.retain_global(imp)
	
	selector = objc_util.sel(str(uuid.uuid1()).replace("-", ""))
	objc_util.class_addMethod(objc_util.object_getClass(cls.ptr), selector, imp, encoding.encode("ascii"))
	return selector

@@ -221,41 +221,9 @@
 rue%0A
-except:%0A%09_HAS_OBJC_UTIL = False%0A%0A
+%09
 _app
@@ -276,16 +276,48 @@
 cation()
+%0Aexcept:%0A%09_HAS_OBJC_UTIL = False
 %0A%0Adef gu
@@ -367,12 +367,14 @@
 ise 
-Name
+Import
 Erro

Fix guard_objc_util