Tag Archives: Cocoa

Catch JavaScript exceptions in UIWebViews

A small but useful category method on UIWebView: Turn uncaught JavaScript Exception into a NSError! // // Created by Marcus Rohrmoser on 05.12.13. // Copyright (c) 2013 Marcus Rohrmoser mobile Software. All rights reserved. //   #import "UIWebView+JavaScriptNSError.h"   #define NSERROR_UIWEBVIEW_SCRIPT @"NSERROR_UIWEBVIEW_SCRIPT" #define NSERROR_UIWEBVIEW_SCRIPT_CODE 1   @implementation UIWebView(JavaScriptNSError)   -(NSString *)stringByEvaluatingJavaScriptFromString:(NSString *)script error:(NSError * __autoreleasing *)error […]

UIColor from hex string, once again

I end up doing this once per year – at least it’s getting leaner each time. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 […]

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: 1 2 3 4 5 6 7 8 9 […]

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