Finally, I post this question to apple forums. Glad to receive apple reply, This was a bug in ARC versus the Objective-C runtime. It has been fixed but I don't think any iOS release has the change yet. The safest solution is to call objc_allocateProtocol() and objc_registerProtocol() in a non-ARC...

Just use NSMutableString; mutability is why it exists. ;) NSString is constant. Not just "wraps a const char *" constant, but "no, really, this thing is immutable and the storage details are entirely opaque to you". In fact, an __NSCFConstantString isn't even stored on the heap at all; there will...

(1) Where does these details like super class, method list etc. stored now? In ObjC 2.0 all the class details are private implementation details. Maybe the data layout remained actually the same, maybe not. (2) Why can't I access the field name? The header file you quoted says that in...

Yes, you missed something essential as you suggest. From the documentation for respondsToSelector: You cannot test whether an object inherits a method from its superclass by sending respondsToSelector: to the object using the super keyword. This method will still be testing the object as a whole, not just the superclass’s...

+[NSObject isSubclassOfClass:] is a class method for NSObject and not all classes are subclasses of NSObject. It seems as if you have find private class that is not a subclass of NSObject, so it requires a more delicate handling for checking for inheritance. Try: BOOL isSubclass(Class child, Class parent) {...

The call you have to objc_setAssociatedObject will cause the object to be retained — that's the OBJC_ASSOCIATION_RETAIN_NONATOMIC part. That being the specified behaviour, it'll also automatically be released when the object with which it is associated is released. So you don't need to do any further memory handling whether you're...

It is not possible to transform an object into an instance of a subclass in Objective-C. However, with the class below you can supply an instance of both the object and the subclass and have the values of all properties copied to the subclass instance. This implementation works with both...

Because of calling conventions at a minimum (with ARC, there are more reasons, but calling conventions have always been a problem). You may have been told that [foo someMethod] is converted into a function call: objc_msgSend(foo, @selector(someMethod)) This, however, isn't exactly true. It may be converted to a number of...

On iOS 8 or Yosemite, use dispatch_queue_create("com.xxx.yyyyy", dispatch_queue_attr_make_with_qos_class( DISPATCH_QUEUE_CONCURRENT, qos, prio)); (with qos/prio the desired quality of service/relative priority values) On earlier OS versions, use dispatch_set_target_queue() to target your queue at the global concurrent queue with the desired priority. Both of these topics have been covered in some detail in...

I found the error and I'm posting here just for the sake of completion. In class X I was declaring shared as + (instancetype)shared { static id _shared = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ _shared = [self new]; }); return _shared; } And I was not implementing shared in...

You're using method_invoke wrong. One must never actually call method_invoke directly. It doesn't know what arguments to expect. That is why its declaration, in the documentation, is written in a completely open-ended form: id method_invoke ( id receiver, Method m, ... ); One must first cast the method_invoke function to...

The associated object functions can be used in any code; the code just needs to have a reference to the object to which you which to associate another object, a reference to the object you wish to associated, and access to the unique key value. So yes, you can use...

"Messages" is the conceptual understanding of method calls in ObjC; in practice it's just a dynamic dispatch mechanism. The call still happens and returns synchronously on the thread that you make it from. ObjC messaging doesn't work like a per-thread message pump like, e.g. Windows messages which it sounds like...

This is a fairly simple check to make sure you don't have any improperly encoded arguments: BOOL isMethodSignatureValidForSelector(NSMethodSignature *signature, SEL selector) { // This could break if you use a unicode selector name, so please don't do that :) const char *c_str = sel_getName(selector); unsigned numberOfArgs = 2; while (*c_str)...

You'll have to stop using cocoapods and start using your own branch of the git repo, with your modified constant. Another approach is to modify the source so that this constant can be configured at runtime (i.e. no longer a constant) and send a pull request to the author. Viva...

The difference is minor, but important. The compiler is issuing a function call, not to objc_msgSendSuper, but to objc_msgSendSuper2. What's the difference, you may ask? It's minor, but important. From apple's open source: /******************************************************************** * * id objc_msgSendSuper(struct objc_super *super, SEL _cmd,...); * * struct objc_super { * id receiver;...

First, it's hard to translate that code to Swift without knowing what you used that class object for in Objective-C. In Objective-C, class objects are objects, and the type Class can hold a pointer to any class object. However, when Objective-C APIs are bridged to Swift, the type Class is...

I wrote that error message!• Either change the class name or don't link against said library. How is your project configured? Is there anywhere where you explicitly link against SR? Or is it a product of linking against two static libraries that both already include SR? If the former, then...

If you want to globally change a class's behavior, rather than play with class identities, the direct approach would just be to replace the method you want replaced. The runtime still allows this, with class_replaceMethod(). That seems like the simplest way to accomplish what you want here.