objective-c-runtime

retainCount in blocks show extrange behavior

 ̄綄美尐妖づ 提交于 2019-12-09 03:47:47
问题 I got the this code in a class: - (void)cancel { if (_cancelBlock) _cancelBlock(); } - (void)overrideCancelWithBlock:(void(^)(void))cancelBlock { [_cancelBlock release]; NSLog(@"AsyncOperation-overrideCancelWithBlock-[cancelBlock retainCount]=%lu (before)", [cancelBlock retainCount]); _cancelBlock = [[cancelBlock copy] retain]; NSLog(@"AsyncOperation-overrideCancelWithBlock-[_cancelBlock retainCount]=%lu (after)", [_cancelBlock retainCount]); } - (void)dealloc { NSLog(@"AsyncOperation-dealloc

Deploying to OS X 10.6 and “-fobj-arc is not supported on platforms using the legacy runtime”

时光毁灭记忆、已成空白 提交于 2019-12-08 16:16:41
问题 Background: I'm building an app for OS X with deployment target of 10.6. I have not converted my app to ARC completely, but I am adding a few new classes which would benefit from ARC, so I have set the -fobj-arc compiler flag for those classes. Compiling fails for Universal 32/64-bit Intel architecture, with error -fobj-arc is not supported on platforms using the legacy runtime . Building for 64-bit only succeeds. I'm not well versed in low level architecture. My question is: what is the

Can't subclass DispatchGroup - “only visible via the Objective-C runtime”?

亡梦爱人 提交于 2019-12-08 04:02:34
问题 It's not possible to subclass DispatchGroup , how to do so? Note: this has finally been fixed in iOS 10+ Example, carry a stateful package with a group, class PushDispatchGroup: DispatchGroup { var sentIds: [(tableName: String, rowId: String)] = [] } thanks to shallowThought for pointing out this is fixed in iOS10. 回答1: how to inherit from a class which is 'only visible via the Objective-C runtime'? You don't. This is not wrapped around a proper "object" the way you're thinking about it. It's

Whats is methodLists attribute of the structure objc_class for?

余生长醉 提交于 2019-12-08 02:21:52
问题 Looking inside the runtime.h, I found the definition of the structure objc_class. Among various members, We have this :- struct objc_method_list **methodLists We definitely need to know what all methods a class has, But a list of methods should be fine, but why do we have "lists" ? Why not just one list ? Also, can anyone specify that, Are methods inherited from superclass part of that list or we get to them via superclass pointer that points to parent class's structure. 回答1: The purpose is

Objective C - Get argument types of a method?

风流意气都作罢 提交于 2019-12-08 02:13:52
问题 At runtime I need to be able to get the argument types of a method. The following is what gets printed: I have read on other threads that at run-time time objective c treats all objects passed to a method as arguments as id . If this approach doesn't work any other suggestions on a way to read argument types? Log 2014-02-07 15:47:08.962 OCInjection[55727:70b] @ 2014-02-07 15:47:08.964 OCInjection[55727:70b] : Code Class class = NSClassFromString(injectionBinding); unsigned int methodCount;

objc_getProtocol() returns NULL for `NSApplicationDelegate"?

社会主义新天地 提交于 2019-12-07 04:37:16
问题 I'm trying to use the objc_getProtocol() function to get a reference to the struct representing the NSApplicationDelegate protocol: Protocol *protocol = objc_getProtocol("NSApplicationDelegate"); However, for some reason, this always returns NULL . Other protocols such as NSObject , NSCoding , NSTableViewDelegate , and NSTableViewDataSource work fine. Is there something special about NSApplicationDelegate , or am I doing something wrong? 回答1: Found the answer in the Apple docs: http:/

ios 6 and 7 doesnt return same results

有些话、适合烂在心里 提交于 2019-12-07 04:20:18
问题 It seems that our apps which use getPropertyType(..) are failing under ios7. For whatever reason, getPropertyType(..) on for example a NSString property returns NSString$'\x19\x03\x86\x13 as the type, instead of just NSString, and also instead of NSNumber it returns NSNumber\xf0\x90\xae\x04\xff\xff\xff\xff . All of this is causing some tricky problems when i later on check against a specific type. I have changed this (legacy?) code to use isKindOfClass instead, but it bothers me that I don't

Xcode — finding dead methods in a project

久未见 提交于 2019-12-07 03:23:47
问题 I am curious if there are any tools that provide partial solutions for this. It is a tricky problem because of performSelector . . . but a tool ought to at least be able to come up with candidates, making the human's job easier. 回答1: Using static analysis, it is impossible to detect functions/methods that are defined but not used due to dynamic nature of Objective-C. The only reasonable solution is to run a coverage using GCov or similar tool. Even then, you will have to make your program do

How to call an implementation with variable number of arguments?

若如初见. 提交于 2019-12-07 03:16:40
问题 To simplify, let's say I have a function like that void myFunc(id _self, SEL _cmd, id first, ...) { } In that method I wanna call the implementation(imp) on the superclass of _self. I can reach that IMP with this code: Class class = object_getClass(_self); Class superclass = class_getSuperClass(class); IMP superimp = class_getMethodImplementation(superclass, _cmd); now, how can I do to call that imp ? 回答1: Just call it using variable arguments: superImp(self, _cmd, argument1, argument2,

Objective-C Address of property expression

為{幸葍}努か 提交于 2019-12-07 01:54:14
问题 I need access address of property but have problem. example code is @interface Rectangle : NSObject { SDL_Rect wall; SDL_Rect ground; } @property SDL_Rect wall; @property SDL_Rect ground; @end @implementation Rectangle @synthesize x; @synthesize y; @end @interface Graphics : NSObject { int w; int h; } -(void) drawSurface @end @implementation Graphics -(void) drawSurface { Rectangle *rect = [[Rectangle alloc] init]; SDL_BlitSurface(camera, NULL, background, &rect.wall); } @end &rect.x is