objective-c-blocks

Is it possible to compare two Objective-C blocks by content?

float pi = 3.14; float (^piSquare)(void) = ^(void){ return pi * pi; }; float (^piSquare2)(void) = ^(void){ return pi * pi; }; [piSquare isEqualTo: piSquare2]; // -> want it to behave like -isEqualToString... ...

Encoding an Objective-c Block?

Is it possible to encode an objective-c block with an NSKeyedArchiver? I dont think a Block object is NSCoding compliant, therefore [coder encodeObject:block forKey:@"block"] does not work? Any ideas? ...

Use of ivar in block returned to other object

I have found a crash in an iPhone application with target iOS 4 that changes depending on the type of build. The debugger is giving me nothing much to go on, it stops at UIViewController *result = [self factory](self); with EXC_BAD_ACCESS. self is a class inheriting from NSObject (shown below as NSObjectInheritor). Zombies are ena...

What does this ^ syntax mean in Objective-C ?

In iPhone SDK 4.0 UIApplication has a new method, setKeepAliveTimeout that requires a second parameter of type 'void(^)(void)'. -(BOOL)setKeepAliveTimeout:(NSTimeInterval)timeout handler:(void(^)(void))keepAliveHandler What exactly does the syntax of the second param mean, and how would I declare a function/handler that I can pass into...

What is (double (^)(int))foofoo

There is an example on cdecl that goes (double (^)(int))foofoo means cast foofoo into block (int) returning double. What does it mean to cast foofoo into a "block" of int? What does the symbol ^ exactly mean in this context. Usually it is bitwise XOR. ...

Objective-C block not being released for background-only applications

I have an application that runs in the background only (by specifying LSBackgroundOnly in the info.plist file). The problem is, that all blocks that I run on parallel queues are not being released. The (simplified) code looks like below. Blubber is just some dummy class that holds an NSDate for testing. Also, it overwrites retain, rele...

Objective-C Block which accepts an object and returns a boolean.

Can you please write for me a block which conforms to this definition: (BOOL(^)(id))block. The closest I have gotten is: typedef BOOL (^birds)(MyObject*); birds c = ^(MyObject* p){ return (BOOL)[p.something boolValue]; }; But it seems passing this c in a message who wants (BOOL(^)(id))block is a no go. ...

UIScrollView touch events during animation not firing with animateWithDuration: but work fine with UIView beginAnimations:

I have a UIScrollView subclass that I am programmatically scrolling using UIView animations. I'd like the user to be able to tap or zoom into the UIImageView content of the Scroll View while the animation is taking place. This has worked fine while using a formulation akin to this: - (void) scrollSmoothlyatPixelsPerSecond:(float)thePi...

Freeing Objects in Objective-C Blocks

When using an Objective-C object that returns asynchronously with a completion handler, like AVAssetExportSession, is there anything wronmg with code like this: AVAssetExportSession* exportSession = [[AVAssetExportSession alloc] initWithAsset: composition presetName: AVAssetExportPresetHighestQuality]; [exportSession exportAsynchronousl...

Turning a NSDictionary into a string using blocks?

I'm sure there is a way to do this using blocks, but I cant figure it out. I want to to turn an NSDictionary into url-style string of parameters. If I have an NSDictionary which looks like this: dict = [NSDictionary dictionaryWithObjectsAndKeys:@"blue", @"color", @"large", @"size", nil]]; Then how would I turn that into a string that ...

Xcode linker and blocks: Undefined symbol "___block_global_1"

I am trying to build an application in Xcode 3.2.4 and am getting the following linker error: Undefined symbols: "___block_global_1", referenced from: ___block_holder_tmp_1.120 in foobarbaz.o ld: symbol(s) not found collect2: ld returned 1 exit status I'm at a loss to explain what I've done in my source file that might be caus...

How to comment Apple's block extension for Doxygen 1.7.2?

Doxygen annouced in their changelog for version 1.7.2 to support Apple's block extension. I wonder what the syntax is to generate the documentation. I could not find any hint - also not in the Doxygen configuration file (version 1.7.2). ...

Objective-C blocks as properties. Am I crazy?

Is that possible? ...

Objective C Blocks: Is there a way to avoid 'self' being retained?

Hello everyone, I'm trying to write this down as concisely as possible, but it's not easy to describe -- so thanks for reading =) I'm the main developer of the Open Source iPhone Framework Sparrow. Sparrow is modeled after the Flash AS3 Library, and thus has an event system just like AS3. Currently, that system works by specifying sele...

How to write Objective-C Blocks inline?

I am trying to implement a binary search using objective-c blocks. I am using the function indexOfObject:inSortedRange:options:usingComparator:. Here is an example. // A pile of data. NSUInteger amount = 900000; // A number to search for. NSNumber* number = [NSNumber numberWithInt:724242]; // Create some array. NSMutableArray* array = ...

Blocks instead of performSelector:withObject:afterDelay:

I often want to execute some code a few microseconds in the future. Right now, I solve it like this: - (void)someMethod { // some code } And this: [self performSelector:@selector(someMethod) withObject:nil afterDelay:0.1]; It works, but I have to create a new method every time. Is it possible to use blocks instead of this? Basi...