February 2012
13 posts
3 tags
Creating retain cycles by misusing assertions
I’d like to talk about the dreaded retain cycles that often happen unexpectedly, using this wrong sample: __block __typeof__(self) nrSelf = self; self.onSomething = ^ (BOOL someCondition) { NSParameterAssert(!someCondition); // Wrong! [nrSelf doSomethingElse]; }; The block causes self to leak. Reason? Check how NSParameterAssert is expanded in NSException.h and compare it with...
Feb 28th
1 note
4 tags
Scroll View quirks, Event handling, and the Run...
Many iOS apps are built upon table views that need to be updated on-demand. This article presents a rather simple solution to the problem: Update the scroll view, continuously, but only when the user is not touching it, so the scrolling and bouncing is not obstructed (and broken) by the updates. I originally tried a makeshift solution, a couple of years ago, including a...
Feb 28th
1 note
6 tags
C3PO: Hassle-free Localization →
Just updated my C3PO fork with some added info in its README. The script was written by Jamie. On the vouching part, check the PBXProject object in your pbxproj file, and you’ll see a knownRegions. That is an exhaustive list of locales your app is expected to serve, and if anything doesn’t pass muster your app is broken. Oh, and even if you can’t use a framework target without (seriously)...
Feb 26th
3 tags
IRDeployment newly documented →
I’ve also updated documentation for IRDeployment. Now the ever-changing part of the CI workflow — the provisioning profile and the developer identity — is hosted as a Gist, and life is good. IRDeployment is basically a script that builds an iOS project using xcodebuild, and punts it on TestFlight.
Feb 26th
2 tags
Managing content size of UIViewController +...
There seems no reason to manually set and observe things again. Provlded that you wrap it in a navigation controller, this works: + (NSSet *) keyPathsForValuesAffectingContentSizeInPopover { return [NSSet setWithObjects: @"tableView.contentInset", @"tableView.contentSize", nil]; } - (CGSize) contentSizeForViewInPopover { return (CGSize){ 320, ...
Feb 22nd
3 notes
Inventing on Principle (Bret Victor; CUSEC 2012) →
Belated: Magic Ink: Information Software And The Graphical Interface
Feb 17th
Eventually, people get better. A matter of time frames.
Feb 15th
3 tags
Tidying HTML on iOS
This snippet saved me a couple of hours wrestling with libXML. If performance is not that important you can use JavaScript: NSString *tidyString = [self.webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat: @"(function tidy (string) { var element = document.createElement('DIV'); element.innerHTML = string; return element.innerHTML; })(unescape(\"%@\"));", [aString...
Feb 13th
5 tags
Polyfill in Objective-C
This is mostly a snippet, taken from that kitchen sink project, to illustrate the point. The idea is: Make your baggage small. Test for method existance and framework version if you want it to be safe, because it’s human behavior to publicize an existing private API. Method might exist, but with an incomplete implementation that works differently. Use class_addMethod() for this. Provide...
Feb 11th
1 note
TransactionKit →
I’m curious.
Feb 3rd
3 tags
Running Unit Tests from the CLI via Xcode 4
First make your test target depend on the actual app, then do this: $ xcodebuild build -target $TARGET_NAME -configuration $BUILD_CONFIGURATION -sdk iphonesimulator SYMROOT="$TEMP_DIR" It’ll then build and run like a normal build operation. I have not yet looked into any way to configure Test Document Data / Test Location via the CLI without resorting to scripting yet.
Feb 1st
2 notes
2 tags
Conditional Objective-C blocks
This trick allows use of conditional blocks thru the C preprocessor: // Mix and match #if USES_TESTFLIGHT #import "TestFlight.h" #define TESTFLIGHT(...) do { (__VA_ARGS__)(); } while (0) #else #define TestFlight (id)nil #define TESTFLIGHT(...) do { } while (0) #endif
Feb 1st
2 tags
IRDeployment →
A tiny shell script that builds stuff thru `xcodebuild` because Jenkins configuration is hard enough.
Feb 1st
January 2012
3 posts
Jan 28th
2 tags
Super Poking
This lets you know if it’s safe to call super: + (BOOL) superMethodDiffers:(SEL)aSelector { Method ownMethod = class_getClassMethod([self class], aSelector); Method superMethod = class_getClassMethod([self superclass], aSelector); return (superMethod && (superMethod != ownMethod)); } - (BOOL) superMethodDiffers:(SEL)aSelector { Method ownMethod =...
Jan 26th
3 notes
5 tags
-waitUntilAllOperationsAreFinished
The Problem Unbounded problems aren’t easy to resolve because most SDKs and toolkits are designed to resolve one-off problems, for example: List the contents of this directory, then when you’re done give me a call. If you’re dealing with local resources, you’ll almost always use a synchronous method that smells pretty procedural (like NSFileManager). No trouble to be had there. :) If...
Jan 26th
December 2011
4 posts
6 tags
Drawing single-line-height text without abandoning...
Core Text is lightweight and all awesome. But we have this pesky little problem with multilingual layouts — different fonts are created by different vendors and typographers, and they often mismatch in terms of metrics. Some are taller, some shorter; some have huge ascender and descenders, some relatively tiny and tame. Things are quite manageable with just one language, but it’s not the case...
Dec 28th
1 tag
on making good stuff →
The fact that Valve released a Portal 2 OST with Lisp references in song titles alone, explains why Valve is an unique place to work at. You don’t tile Mecca with the finest marble, though. Vestiges of greatness always simmer through the product. Ship great, but don’t take forever. Make awesomely great products. Some people never get this, and get lost in a sea of mediocrity, others, perhaps,...
Dec 17th
1 note
Xcode’s `ld` missing for Simulator →
There’s another ld in /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain if you were playing with the latest stuff and can’t build for the Sim.
Dec 14th
3 tags
“What I suspect Google is up to with Native... →
If I am understanding it correctly: the Web is hot because it delivers stuff that can be effortlessly maintained. NaCl allows delivery of secure and safe binaries by using sandboxes and perfect static analysis. NaCl runs atop a browser (a “host app”), in a world where abstrations no longer matter, performance-wise. Isn’t it fundamentally the same thing as the App Store and Sandboxing? ...
Dec 7th
7 notes
November 2011
9 posts
5 tags
IRWMFKit →
WMF ➡ CGImageRef, because wv and UniConverter are both GPL/LGPL, and GPL/LGPL is evil (“incompatible with the App Store”). How? NSBundle *ownBundle = [NSBundle bundleForClass:[self class]]; NSString *wmfPath = [ownBundle pathForResource:@"Image" ofType:@"wmf"]; NSData *wmfData = [NSData dataWithContentsOfMappedFile:wmfPath]; IRWMFDocument *document = [IRWMFDocument...
Nov 23rd
3 tags
IRTextAttributor
IRTextAttributor is a simple class that solves the problem where I’d like to attribute a certain string asynchronously. For example, given the string: Google.com is here. I’d like it to eventually look like: Google.com (“Search the world’s information, including webpages, images, videos and more. Google has many special features to help you find exactly what you’re looking for.”)...
Nov 16th
2 notes
Nov 13th
1 tag
Inbound Taste of Code
What makes Jobs memorable is different from what makes Ritchie memorable. Ritchie introduced building blocks for the modern world, but Jobs (or people who worked with Jobs) took them and built something directly manipulatable with them. What made Jobs great is not about grand paradigm shifts, but relentless polish concentrating on the front-end. What’s wrong with many technology solutions is...
Nov 12th
How long did it take you from judging Objective-C’s eerie square brackets in curious eyes, to mastering the language or even using it exclusively in professional projects?
Nov 12th
2 tags
Kings of User Convenience
Placeholders and Thumbnails There is only one piece of authentic resource. Previews, proxies, thumbnails, and other auxiliary objects are merely conforming representations that mainly bring programmer or user convenience. Lower-quality placeholders are proxies providing mostly an illusion of perceived performance. They look like the real thing, and they load a lot more faster. So showing...
Nov 11th
4 notes
Idea for implementing live reordering for any UI
After staring at a blank Core Text editor for a while, I understood this: To implementing live reordering for any UI, The underlying model should be separable from the global truth You should have an interstitial model for the view The reordered item can be moved around in the interstitial model You should support an interstitial display style for the view You should have good state...
Nov 5th
Commoditization usually happens when the love is gone.
Nov 3rd
2 tags
Why I still have faith in Objective-J
The native/web debacle only looks like a conundrum when what that are moved thru the pipes were regarded as applications. They are not — what that were actually distributed are experiences. Thru native code, delivery is easy and it takes less time. HTML and JS, althouth both high-level and expressive, are not designed for app development; they play the role of assembly. Great advancements in...
Nov 3rd
1 note
October 2011
8 posts
4 tags
Dealing with side effects of UIView animation
UIView’s animation methods (both the -beginAnimations:context:/-commitAnimations, and the blocks-based APIs introduced in iOS 4) do a lot of work for you. They are implicit, and all super effective. Occasionally (and inevitably) you’ll hit cases where you wish you could work around it without losing all the inference you’ve been enjoying. Fortunately, this seems to work: [UIView...
Oct 24th
8 notes
2 tags
Touch Notation Rebound →
This is a PDF file I created for Matt Gemmell’s Touch Notation suitable for print.
Oct 23rd
2 notes
3 tags
Harmless UINavigationController Swizzling — Redux
Forget all the hard work swizzling stuff and making things conform to NSCoding, it’s not always easy anyway. You can simply call -initWithRootController: twice. That’s the spirit. UIViewController *emptyVC = [[[UIViewController alloc] init] autorelease]; __block WANavigationController *navController = [[[WANavigationController alloc] initWithRootViewController:emptyVC]...
Oct 17th
6 tags
Flipping with proper perspective distortion in...
An ordinary flip transition in UIKit (for example, one you bring up with UIViewAnimationOptionTransitionFlipFromLeft or UIViewAnimationOptionTransitionFlipFromRight) goes like this: The “front” view rotates 180° clockwise or counterclockwise The “back” view simultaneously rotates 180° clockwise or counterclockwise from behind There is visible perspective distortion (me gusta) In the middle of...
Oct 15th
14 notes
Oct 15th
6 tags
IRLifetimeHelper →
This experimental class allows you to say something like: [someObject irPerformOnDeallocation: ^ { [[NSNotificationCenter defaultCenter] removeObserver:aNotificationCenterObject]; }]; This class was written because I wanted to provide a read-only NSManagedObjectContext that updates itself. This allows the single context to be shared among many view controllers. As long as none of the...
Oct 8th
2 notes
4 tags
Harm-free Class Swizzling with NSKeyedUnarchiver
I came across a problem where we need to subclass UINavigationBar in an UINavigationController. Conventionally, one may subclass the navigation controller, and commence hacks. Fortunately, NSKeyedArchiver saves the day: self.window.rootViewController = (( ^ { // Since it is totally unsafe to modify the navigation controller, the best way to swizzle-in a custom navigation bar subclass is...
Oct 3rd
4 tags
Providing default user defaults
NSUserDefaults is fun and practical. Assuming you’ve got an IRDefaults.plist in your app bundle, this registers everything in the dictionary as default user defaults: void IRRegisterUserDefaults () { NSURL *defaultsURL = [[NSBundle mainBundle] URLForResource:@"IRDefaults" withExtension:@"plist"]; NSData *defaultsData = [NSData dataWithContentsOfMappedFile:[defaultsURL path]]; ...
Oct 2nd
1 note
September 2011
9 posts
Sep 19th
4 tags
Customizing UITabBar (Or, tenuous principles to...
UITabBarController is cool, but (un)fortunately it has only one flavor. People might resort to brute-force, re-creating the entire controller from scratch. This is extremely troublesome: a) it takes a lot more effort; b) it needs reverse engineering; c) quirk-for-quirk compatibility is not fun. Most of the time, you’ll want to skin the thing, not create a new thing that works like the old...
Sep 19th
6 notes
1 tag
Tale of a Computer Atheist
Algorithms are common. Pixels, cheap. Ideas a dime a dozen. Ambivalence augmented.
Sep 8th
2 notes
4 tags
Managing iOS Crash Reports with PLCrashReporter
I often hear that when your product grows so big you need to assess and prioritize bugs based on the amount of reports per bug you get. (I do hope that you’ll never have too many bugs and need to prioritize them!) This is how we currently manage bugs: Bugs are caught by PLCrashReporter. I’ve got a fork somewhere as well for Lion + Xcode 4 + iOS targets. I’ve got an...
Sep 8th
5 tags
Acquiring proper UIImage decoding performance
UIImage is lazy, and lazy is good. Lazy is only bad when it’s late to play catch up on required work. Since it never does any decoding unless somebody actually needed the bytes it represents, caching NSData objects read from flat files on the disk then spitting out new UIImage objects obviously doesn’t help presentation at all. The scrolling is often sluggish because it can’t reach 60 FPS. It...
Sep 8th
Ship early and often if it’s a commodity. Like a time tracker. Otherwise ship great, just don’t take forever. You’ll “get” the timing after a few. Any app you fondly love is likely of the scale of an indie movie production — exceptions are scarce. Remember that you, who make things, are the sole and final arbiter of your product.
Sep 7th
Group therapy is like matchmaking; it’s for the weaklings who can’t control their own fate.
Sep 5th
5 tags
IRDiscreteLayoutManager →
This has been alive for a couple of weeks. Please help by looking at it. The discrete layout manager is an experimental shot at creating easy, extensive, expressive magazine-style layouts for iPad apps.
Sep 3rd
3 notes
Shifty
Commoditization of software development happens. There is only so much room at the top. The bottom, though, is always open.
Sep 3rd
August 2011
15 posts
A successful salon gives curly-haired girls...
Me: Just got my hair straightened.
Colleague: Really? **look of disbelief**
Me: Yeah. **died a little bit inside**
Aug 29th
5 tags
gh://evands/xcodeRemoteDeviceFixer →
This fixes a bug where Xcode 4.1 eats up epic amounts of CPU when you’ve got an iOS 5 device which works over Wi-Fi sync. Got one solid hour of MacBook Air battery life back. (This thing is basically a big battery with a Mac wrapper.)
Aug 29th
23 notes
Aug 28th
2 tags
Undocumented way to pass the buck
If you have xcconfig files, using $(inherited) in build configurations helps a lot. It means “also use anything the previous level has defined”. Where can (inherited) be used? XCode, oh how you hurt me
Aug 28th
1 note