Menu
  • HOME
  • TAGS

NSInvocation with primitive using getReturnValue

ios,objective-c,nsinvocation

Well if you wanted to do it with int, it would be enough to simply change it to returnValueContainer:(int *)returnValueContainer. If you want it to work for all types, you can just do returnValueContainer:(void *)returnValueContainer and let the caller pass in a pointer to the correct type. (By the way,...

iOS:Class method added by class_addMethod can't be used by NSInvocation

ios,runtime,selector,class-method,nsinvocation

You need to pass the signature string of the method as the 4th argument of class_addMethod. You are passing NULL.

How to store an init call in an NSInvocation?

objective-c,nsarray,uipageviewcontroller,nsinvocation

Sounds like you want some kind of lazy instantiation. You can use this helper class @interface LazyObject : NSObject @property (copy) id (^block)(void)); @property (readonly) id object; + (instancetype)create:(id (^)(void))block; @end @implementation LazyObject { id _object; } + (instancetype)create:(id (^)(void))block { LazyObject *obj = [[self alloc] init]; obj.block = block;...

Get object array argument from NSInvocation with ARC

ios,arrays,automatic-ref-counting,nsinvocation,message-forwarding

Your method does not take an array parameter -- it takes a pointer parameter. In C, it's not possible to have a parameter of array type. If you write a parameter of type "array of X", it is automatically changed to type "pointer to X". Objective-C methods are C functions,...

EXC_BAD_ACCESS crash on arm64 when use NSInvocation

ios,nsinvocation,arm64

This is what have for the same purposes. + (void)callSelectorWithVarArgs:(SEL)selector onTarget:(id)target onThread:(id)thread wait:(BOOL)wait, ... { NSMethodSignature *aSignature = [[target class] instanceMethodSignatureForSelector:selector]; if (aSignature) { NSInvocation *anInvocation = [NSInvocation invocationWithMethodSignature:aSignature]; void * arg; int index = 2; [anInvocation setSelector:selector]; [anInvocation setTarget:target]; va_list args; va_start(args, wait); do { arg = va_arg(args, void...

NSUndoManager Delayed Argument Evaluation

objective-c,nsundomanager,nsinvocation

As in any method call, it just a question of what happens where. If you don't want [self.aMutableArray objectAtIndex:0] evaluated now, don't include it in the invocation expression! Instead, make the invocation expression a call to a method where that method will call [self.aMutableArray objectAtIndex:0]: [[self.undoManager prepareWithInvocationTarget:self] doSomethingWithObjectAtIndex:0]; ...where doSomethingWithObjectAtIndex:...

NSInvocation invoke giving bad access in iOS 8

reflection,ios8,invoke,nsinvocation

[invocation setArgument:(__bridge void *)(self.valoresEntrada) atIndex:2]; is wrong. You need to pass a pointer to the value being passed. Something like // I don't know the type of self.valoresEntrada, but you can use the type directly typeof(self.valoresEntrada) temp = self.valoresEntrada; [invocation setArgument:&temp atIndex:2]; Also, if you are going to store the...

Firing methods in sequence

ios,cocoa,methods,nsinvocation

I found the best answer here The answer is to replace the whole thing with this: #import <objc/message.h> - (BOOL) numbersPassedAllTests:(NSArray *)numbers { NSInteger count = [TESTS count]; for (int i=0; i<count; i++) { NSString *aMethodName = TESTS[i]; SEL selector = NSSelectorFromString(aMethodName); BOOL (*BOOLMsgSend)(id, SEL, id) = (BOOL (*)(id, SEL,...

NSProxy and forwardInvocation: invoke called within a block causes nil return value

ios,block,retain,nsinvocation,nsproxy

To perform an operation when your invocation is complete, passing the result: if (authenticationRefreshNeeded) { [self.realAPI refreshWithBlock:^(NSObject *someObject) { NSURLSessionDataTask *resultTask = nil; [invocation invokeWithTarget:self.realAPI]; [invocation getReturnValue:&resultTask]; if (completion != nil){ completion(resultTask); } }]; } Where completion() is a block that takes an NSURLSessionDataTask as a parameter. Blocks can be...

objc variadic arguments with primary type and objects

ios,nsinvocation,variadic-parameter

You need to look into Message Forwarding. - (void)forwardInvocation:(NSInvocation *)anInvocation { if ([self.lowerLayer respondsToSelector:[anInvocation selector]]) { [anInvocation retainArguments]; // Thanks newacct dispatch_async(self.mySerialQueue, ^{ … [anInvocation invokeWithTarget:self.lowerLayer]; void *returnValue; [invocation getReturnValue:&returnValue]; NSDictionary *response = (__bridge NSDictionary *)returnValue; … }); } else { [super forwardInvocation:anInvocation]; } } I forgot to include the...

addTarget fails for NSInvocation/invoke pair

ios,nsinvocation

addTarget:action:forControlEvents: does not retain the target. Your NSInvocation object is created locally inside the function and it will be deallocated at the end of the function when nobody has a strong reference to it. Then the button will send a message to a deallocated instance, causing all sorts of bad...