Tag Archives: Cocoa

Vortrag: Index Suche mit CoreData und SQLite

Gestern gab’s einen Mini-Vortrag von mir bei den CocoaHeads München:

CoreData (iOS) ist nur mit Tricks dazu zu bringen den Index bei Textsuche zu benutzen,
SQLite Full Text Search (FTS) ist der Hammer.

Die Folien dazu.

High-Res UIImage remote load

Loading UIImages automatically in high-resolution works fine for locally stored images – but if you want to fetch them via remote URL you have to code yourself.

A simple, blocking but backward compatible (iOS >= 3.0, maybe even 2.0 but untested)  implementation could look like this:
@implementation UIImage (MRORemote)

// add the @2x filename suffix
+(NSURL *)url2x:(NSURL …

Vortrag: Parser mit Ragel

Parser mit Ragel – komplizierte Grammatiken und rattenschnelles XML.
Warum Parser bauen?
Was spricht gegen Ad-Hoc Parsing (a.k.a. Gefrickel)?
Quelltext Impression
Wie komme ich drauf?
Anschnallen: Die Bausteine
Beispiel: SVG Path Parser
Beispiel: XML Parser
Ausblick: Zustandsautomaten
Vielen Dank

Die Folien vom Vortrag am 22. September bei den CocoaHeads München.

UILabel with a (custom) CGFont

UILabel’s font property accepts UIFonts – but strange enough there’s no way to get a custom loaded CGFont (from a ttf or otf file) converted into such an UIFont. You’re stuck with the iPhone’s pre-installed fonts – at least when you have to support iOS 3.0 devices.

After googling a bit and searching Stackoverflow I found …

iPhone: libxml2 & RELAX NG validation

Having a validating parser in place can reduce the required code to parse XML a lot – you know very well what you actually get. As mentioned in my last post about RELAX NG & trang, I prefer RELAX NG over W3C XML Schema – which doesn’t matter anyway because Apple’s suggested XML parser …

CocoaHeads Vortrag gestern: Unit Testing

um ein wenig anzugeben und schlicht den Link hier zu platzieren:

Cocoa Unit Testing Folien,
Cocoa Unit Testing Wiki Seite

NSCachedURLResponse / NSKeyedUnarchiver pain

as the iPhone SDK comes with a rather dysfunctional NSURLCache — Apple suggests to implement it from scratch yourself in the code examples about caching — I went for just this.

Until I came across the not restoring userInfo, storagePolicy and data of NSCachedURLResponse.

Couldn’t believe it and spent almost the whole day verifying that …

Binary Search NSArray

Though CFArray comes with binary search capability, NSArray does not – at least not within the iPhone SDK. The indexOfObject:inSortedRange:options:usingComparator: can’t be found.

Plus the CFArrayBSearchValues doesn’t tell you whether the key actually is part of the list or not. That’s what the Java JDK does, so let’s implement some category methods
-(NSInteger)binarySearch:(id)key;
-(NSInteger)binarySearch:(id)key usingSelector:(SEL)comparator;
-(NSInteger)binarySearch:(id)key usingSelector:(SEL)comparator inRange:(NSRange)range;
-(NSInteger)binarySearch:(id)key …

underretain in CoreAnimation / iPhone Simulator

After upgrading to Snow Leopard and XCode 3.2.1 I’ve seen such console output
CAUnderRetain(32139,0xa0391500) malloc: *** error for object 0×3838000: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
when rotating the iPhone Simulator in a project with base SDK 3.0.

This can be reproduced as follows:

Create a fresh iPhone project (I use …

CoreData generic findManyByKey

The base for many of my SELECT-ish queries when querying by exact match is one generic method I created in some category methods on NSManagedObjectContext:
-(NSArray*)entityName:(NSString*)entityName findManyByRelation:(NSDictionary*)dict
{
// TODO handle dict nil and emptyness
NSMutableArray *arr = initWithCapacity:dict.count];
for(NSString *key in dict)
{