diff --git a/src/bundle.rs b/src/bundle.rs index a34b5821..78bac9e5 100644 --- a/src/bundle.rs +++ b/src/bundle.rs @@ -11,14 +11,9 @@ use std::ffi::CString; use std::mem; -use objc::{class, msg_send, sel, Encode, Encoding, EncodeArguments, Message}; -use objc::runtime::{Class, Sel, Method, Object, Imp}; -use objc::runtime::{ - objc_getClass, - class_addMethod, - class_getInstanceMethod, - method_exchangeImplementations -}; +use objc::ffi; +use objc::runtime::{Class, Imp, Object, Sel}; +use objc::{class, msg_send, sel, Encode, EncodeArguments, Encoding, Message}; use crate::foundation::{id, nil, BOOL, YES, NSString}; @@ -73,24 +68,27 @@ extern "C" fn get_bundle_id(this: &Object, s: Sel, v: id) -> id { } } -unsafe fn swizzle_bundle_id(bundle_id: &str, func: F) where F: MethodImplementation { +unsafe fn swizzle_bundle_id(bundle_id: &str, func: F) +where + F: MethodImplementation, +{ let name = CString::new("NSBundle").unwrap(); - let cls = objc_getClass(name.as_ptr()); + let cls = ffi::objc_getClass(name.as_ptr()); // let mut cls = class!(NSBundle) as *mut Class; // Class::get("NSBundle").unwrap(); // let types = format!("{}{}{}", Encoding::String, <*mut Object>::ENCODING, Sel::ENCODING); - let added = class_addMethod( - cls as *mut Class, - sel!(__bundleIdentifier), + let added = ffi::class_addMethod( + cls as *mut ffi::objc_class, + sel!(__bundleIdentifier).as_ptr(), func.imp(), - CString::new("*@:").unwrap().as_ptr() + CString::new("*@:").unwrap().as_ptr(), ); - let method1 = class_getInstanceMethod(cls, sel!(bundleIdentifier)) as *mut Method; - let method2 = class_getInstanceMethod(cls, sel!(__bundleIdentifier)) as *mut Method; - method_exchangeImplementations(method1, method2); + let method1 = ffi::class_getInstanceMethod(cls, sel!(bundleIdentifier).as_ptr()) as *mut ffi::objc_method; + let method2 = ffi::class_getInstanceMethod(cls, sel!(__bundleIdentifier).as_ptr()) as *mut ffi::objc_method; + ffi::method_exchangeImplementations(method1, method2); } pub fn set_bundle_id(bundle_id: &str) { diff --git a/src/foundation/class.rs b/src/foundation/class.rs index 9d2b334b..2398771c 100644 --- a/src/foundation/class.rs +++ b/src/foundation/class.rs @@ -9,7 +9,8 @@ use std::time::Instant; use lazy_static::lazy_static; use objc::declare::ClassDecl; -use objc::runtime::{objc_getClass, Class}; +use objc::ffi; +use objc::runtime::Class; lazy_static! { static ref CLASSES: ClassMap = ClassMap::new(); @@ -83,7 +84,7 @@ impl ClassMap { // runtime, and we can wind up in a situation where we're attempting to register a Class // that already exists but we can't see. let objc_class_name = CString::new(class_name).unwrap(); - let class = unsafe { objc_getClass(objc_class_name.as_ptr() as *const _) }; + let class = unsafe { ffi::objc_getClass(objc_class_name.as_ptr() as *const _) }; // This should not happen for our use-cases, but it's conceivable that this could actually // be expected, so just return None and let the caller panic if so desired. @@ -101,7 +102,7 @@ impl ClassMap { }); } - Some(class) + Some(class.cast()) } /// Store a newly created subclass type.