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...
...
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?
...
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...
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...
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.
...
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...
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.
...
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...
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...
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 ...
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...
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).
...
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...
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 = ...
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...