objective-c-blocks

How to execute a block (identified by pointer) from lldb

可紊 提交于 2019-12-07 17:40:41
问题 I'm in the lldb debugger within the iOS simulator and I have the address for a block. I want to try to execute it. I tried the first thing that came to mind (see below) but it didn't work. Is there a way to do this? (lldb) po 0x2c7140 (int) $2 = 2912576 <__NSGlobalBlock__: 0x2c7140> (lldb) po 0x2c7140(NO, @"Test") error: called object type 'int' is not a function or function pointer I also tried call but apparently that is not a command in llvm? It was available in gdb. (lldb) call (void

NSOperationQueue: Trouble understanding the order [duplicate]

一个人想着一个人 提交于 2019-12-07 14:39:52
问题 This question already has answers here : NSOperationQueue serial FIFO queue (3 answers) Closed 5 years ago . I'm having trouble understanding the way NSOperationQueue works. Say I have: NSOperationQueue *queue = [[NSOperationQueue alloc] init]; queue.maxConcurrentOperationCount=1; [queue addOperationWithBlock:^{ [someObject someSelector]; }]; [queue addOperationWithBlock:^{ [someObject anotherSelector]; }]; The second block is being called even before the first block finishes - the opposite

OCMock and Blocks

陌路散爱 提交于 2019-12-07 12:54:22
问题 I have a method with the following signature that I want to test using OCMock's stub feature: - (void)signInWithEmail:(NSString *)email andWithPassword:(NSString *)password andWithBlock:(void (^)(GNCustomer *customer, NSError *error))block How would I go about mocking this to handle the returned block. I have tried: [[_mockAuthenticationRepository stub] signInWithEmail:[OCMArg any] andWithPassword:[OCMArg any] andWithBlock:^(GNCustomer *customer, NSError *error) { }]; When I try to stub with

How much overhead does a msg_send call incur?

折月煮酒 提交于 2019-12-07 10:33:30
I'm attempting to piece together and run a list of tasks put together by a user. These task lists can be hundreds or thousand of items long. From what I know, the easiest and most obvious way would be to build an array and then iterate through them: NSArray *arrayOfTasks = .... init and fill with thousands of tasks for (id *eachTask in arrayOfTasks) { if ( eachTask && [eachTask respondsToSelector:@selector(execute)] ) [eachTask execute]; } For a desktop, this may be no problem, but for an iphone or ipad, this may be a problem. Is this a good way to go about it, or is there a faster way to

iOS - Unit Testing Asynchoronous code

对着背影说爱祢 提交于 2019-12-07 10:28:51
问题 The part of a method that I am trying to test is as follows: - (void)configureTableFooterView { dispatch_async(dispatch_get_main_queue(), ^{ self.tableView.tableFooterView = nil; if ([self.parser.resultSet isLastPage]) { return; } }); } I have written the unit test as follows: - (void)testTableFooterViewConfigurationAfterLastPageLoaded { id mockTableView = OCMClassMock([GMGFlatTableView class]); OCMExpect([mockTableView setTableFooterView:[OCMArg isNil]]); id resultSet = OCMClassMock(

Is it possible to extend an existing Objective-C Block?

别说谁变了你拦得住时间么 提交于 2019-12-07 08:44:41
问题 I have a class using a Block defined in the header like this: @property (readwrite, copy) RequestSucceededBlock succeededBlock; The property succeededBlock is already set with a Block. Is there a way to override this Block with another that still calls the original, similar to class inheritance? I assume this is not possible, because class inheritance should be used to express things like that. Is it still possible? 回答1: Assuming you're talking about trying to have a replacement block in a

What's the harm of retain self in block?(Objective-C, GCD)

青春壹個敷衍的年華 提交于 2019-12-07 08:04:08
问题 In many guide about how to use blocks and GCD, one tip is always mentioned : do not retain self in block. The detail is when defining a block, if you reference self or a ivar of self, then self is retained by the block. So the work around is to use __block modifier to get a weakSelf or weakIvar . But what's the harm of not doing that? If the block retains self, it should release self when the block is finished(Am I right about this?). So ultimately the reference count of self is balanced. I

ARC: EXC_BAD_ACCESS when calling a method from inside a block, inside a delegate method

孤人 提交于 2019-12-07 07:10:14
问题 I created a block, inside a delegate method and I am using it to call a static method in another class. I am getting an EXC_BAD_ACCESS error even when I have NSZombies enabled. There are a few posts on here about similar problems - I think this one is the closest: ARC: Getting EXC_BAD_ACCESS from inside block used in delegate method But, I haven't found anything so far that has helped. Here is the code: @interface MyClass() @property (nonatomic, copy) CaseBlock c; @end .... //NSURLConnection

Avoiding nested blocks with asynchronous code in objective-c

妖精的绣舞 提交于 2019-12-07 07:03:31
问题 I have a long series of events that needs to happen in my Objective-C code. Lets say I have 6 things - thingA, thingB, thingC, thingD, thingE and thingF. thingB and thingD return a BOOL. If thingB is NO, then thingC doesn't need to be called. If thingD is NO, then thingE doesn't need to be called. - (void)doThings:(void(^)())completion { [self thingA: ^{ [self thingB: ^(BOOL success) { if (success) { [self thingC: ^{ [self thingD: ^(BOOL success) { if (thingD) { [self thingE: ^{ [self thingF]

What's the difference between NSInvocation and block?

依然范特西╮ 提交于 2019-12-07 06:43:06
问题 when i say block i mean: ^(int a) {return a*a;}; besides, block is only support by iOS4 and above. What is the difference between these two? 回答1: An NSInvocation is a message (using a selector) to an object, with optional parameters, which can be executed later (or now), and outside the current context (mind of course what you copy vs retain or reference if you move it). NSInvocation has the benefit that you can selectively copy/refer to exactly what you need. The block is a secret local