Tag Archives: Cocoa

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 doesn’t [...]

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 [NSKeyedUnarchiver unarchiveObjectWithData:...] not restoring userInfo, storagePolicy and data of NSCachedURLResponse. Couldn’t believe it and spent almost the whole day verifying [...]

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; [...]

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 [...]

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 = [[NSMutableArray alloc] initWithCapacity:dict.count]; for(NSString *key in dict) { NSExpression *left = [NSExpression expressionForKeyPath:key]; NSExpression *right = [NSExpression [...]

NSDateFormatter case sensitive trap

Though NSDateFormatter behaves slightly different than documented, the following might even be correct, as strange as it might look (mind the last two lines): -(void)testNSDateFormatterTrap { NSDateFormatter *lower = [[[NSDateFormatter alloc] init] autorelease]; lower.dateFormat = @"yyyy-MM-dd HH:mm:SS ZZZ";   NSDateFormatter *upper = [[[NSDateFormatter alloc] init] autorelease]; upper.dateFormat = @"YYYY-MM-dd HH:mm:SS ZZZ";   lower.timeZone = upper.timeZone [...]

CocoaTouch, CoreData and binary String Search

The query optimiser for NSPredicate queries ontop CoreData/SQLite on the iPhone is a bit rudimentary (cough) and so I had to optimise myself to get binary-search enabled quick results:

Cocoa wrapped regex.h

Strange enough there’s no regular expression class in the iPhone SDK. Update: iOS 4 brings NSRegularExpression. My simple wrapper around the regex.h C API is not safe for unicode matching patterns but does the job e.g. for parsing URLs. If you need more, have a look at RegexKitLite. My simple wrapper has the interface: