nsinvocation

NSInvocation and memory issues [duplicate]

。_饼干妹妹 提交于 2019-12-23 07:47:49
问题 This question already has answers here : NSInvocation getReturnValue: called inside forwardInvocation: makes the returned object call dealloc: (3 answers) Closed 6 years ago . So I come from the Java world where we are blissfully ignorant of memory management issues. For the most part, ARC has saved my butt, but here is something that has got me stumped. Basically I am using NSInvocations for some stuff, and I ran into some nasty memory issues before I made the following code modifications.

NSInvocation and ARC (Automatic Reference Counting)

我们两清 提交于 2019-12-20 20:19:34
问题 When trying to migrate my current code to ARC, I'm getting errors whenever I pass an NSString as an NSInvocation argument. Example: NSInvocation inv = ...; NSString *one = @"Hello World!"; [inv setArgument:&one atIndex:2]; The error happens when I use the Refactor -> Convert to Objective-C ARC option from the Edit menu. The text is "NSInvocation's setArgument is not safe to be used with an object with ownership other than __unsafe_retained." How would I get around this? 回答1: This might work;

NSValue:getValue: strange behavior,why this happens?

夙愿已清 提交于 2019-12-19 09:46:51
问题 I try to pass CGRect to NSInvocation (setArgument:atIndex:). I wrap it by NSValue, push to the NSArry,then get from NSArray and use NSValue (getValue:). Calling of (getValue:) method causes the changing of before declared index NSInteger i. Can anybody say why does this happen? NSString className = @"UIButton"; Class cls = NSClassFromString(className); cls pushButton5 = [[cls alloc] init]; CGRect rect =CGRectMake(20,220,280,30); NSMethodSignature *msignature1; NSInvocation *anInvocation1;

NSValue:getValue: strange behavior,why this happens?

荒凉一梦 提交于 2019-12-19 09:46:23
问题 I try to pass CGRect to NSInvocation (setArgument:atIndex:). I wrap it by NSValue, push to the NSArry,then get from NSArray and use NSValue (getValue:). Calling of (getValue:) method causes the changing of before declared index NSInteger i. Can anybody say why does this happen? NSString className = @"UIButton"; Class cls = NSClassFromString(className); cls pushButton5 = [[cls alloc] init]; CGRect rect =CGRectMake(20,220,280,30); NSMethodSignature *msignature1; NSInvocation *anInvocation1;

Defining an Objective-C Class without a base Class - Compiler Warning

纵饮孤独 提交于 2019-12-19 05:16:24
问题 I'm using the Following NSInvocation code form Matt Gallagher for my Undo/Redo code. Though with the Latest version of xCode I'm not getting a Warning that says: NSInvocation(ForwardedConstruction).m:28:12: Class 'InvocationProxy' defined without specifying a base class The Code works great, but the others on my team (well me too) don't like seeing the Warning. I'd like the Class to be as trim as possible, so I didn't want all the Methods in NSObject. Any Suggestions welcome! Thank you!

Get the sender of the message for an NSInvocation

旧巷老猫 提交于 2019-12-13 00:36:17
问题 How do I get the sender of the message wrapped in an `NSInvocation? I'm in an object, and I've just received an invocation in my forwardInvocation: . Is there any way to know who sent me the message in the first place? 回答1: No. Information about the sender is not available (unless you explicitly add an sender:self argument). See also this thread http://www.cocoabuilder.com/archive/cocoa/194746-is-the-sender-of-an-obj-method-implied-in-the-destination-method.html: It isn't explicitly available

Performing selectors on main thread with NSInvocation

霸气de小男生 提交于 2019-12-12 17:36:05
问题 I want to perform animation on main thread (cause UIKit objects are not thread-safe), but prepare it in some separate thread. I have (baAnimation - is CABasicAnimation allocated & inited before): SEL animationSelector = @selector(addAnimation:forKey:); NSString *keyString = @"someViewAnimation"; NSInvocation *inv = [NSInvocation invocationWithMethodSignature:[workView.layer methodSignatureForSelector:animationSelector]]; [inv setTarget:workView.layer]; [inv setSelector:animationSelector];

Why does this NSInvocation raise an exception?

Deadly 提交于 2019-12-12 15:46:30
问题 I have a real head-scratcher right now. So, an NSTimer object, an NSMethodSignature object, and an NSInvocation object walk into a bar. Here's the rest of the joke: NSMethodSignature *methodSig = [NSMethodSignature methodSignatureForSelector:@selector(setAlphaValue:)]; NSInvocation *inv = [NSInvocation invocationWithMethodSignature:methodSig]; CGFloat alphaVal = 1.f; [inv setSelector:@selector(setAlphaValue:)]; [inv setTarget:tabViewItem.view]; [inv setArgument:&alphaVal atIndex:2]; NSTimer

NSInvocation getReturnValue: called inside forwardInvocation: makes the returned object call dealloc:

廉价感情. 提交于 2019-12-12 08:07:14
问题 Here's a standalone test.m file that I'm using to test the behavior. To compile: clang test.m -o test.app -fobjc-arc -ObjC -framework Foundation . Make sure the Xcode command-line tools are installed. #import <Foundation/Foundation.h> @protocol Protocol @optional - (id)objProxyMethod; @end @interface ReturnObject: NSObject @end @interface Test : NSObject <Protocol> @end @interface Proxy : NSObject <Protocol> - (id)objProxyMethod; @end @implementation ReturnObject - (void)dealloc { NSLog(@

Strange “zombie” in forwardInvocation: + getArgument:atIndex methods

自闭症网瘾萝莉.ら 提交于 2019-12-10 22:09:59
问题 Here is part from my code: - (void)viewDidLoad { [super viewDidLoad]; CGRect frame = [[UIScreen mainScreen] bounds]; _webView = [[UIWebView alloc] initWithFrame:frame]; [_webView setHidden:NO]; [self.view addSubview:_webView]; _vk = [[DPVkontakteCommunicator alloc] initWithWebView:_webView]; DPVkontakteUserAccount *user; NSString *accessToken = [[NSUserDefaults standardUserDefaults] objectForKey:@"accessToken"]; NSInteger userId = [[[NSUserDefaults standardUserDefaults] objectForKey:@"userId"