Here’s a novel, fun, and (I think) not completely stupid way of highlighting source code on the web: Transparent text clipping on a background drawn in css, using the ch and lh units to fit the monospace font grid. Click toggle text clipping to see what I mean: #include <stdio.h> int main() { printf("Hello, World!"); return 0; } The C code is the raw content of a <pre>...</pre> element. There are…
I’ve made an archive of all my public activity on twitter, from 2009 to 2022. I’ve fully switched to mastodon more than two years ago, and this archive has little value, but it is my stuff of little value. I’d be sad to see it gone. Here it is: twitter-archive.bou.io I went the easy way and used this tool by Darius Kazemi on tinysubversions.com. I may spend some time to customize it. Or maybe not.
There’s been some discussion around the iPad’s multitasking user interface , i.e., “how to do several things at once on an iPad?”. The general feeling is that the current UI is clumsy, hardly discoverable; that’s what makes the iPad a consumer device, and not a machine to be used for actual work. I tend to agree, but I don’t think the current state of the Mac user interface is much better. Let’s…
English title, if I ever translate it: “A brief history of french/european daylight saving time policies”. Ce post reprend un thread twitter d’octobre 2016. Quitte à le recycler régulièrement, autant l’héberger moi-même. Aujourd’hui on change d’heure - on passe de UTC+2 à UTC+1. Alors que le méridien de Greenwich traverse la France. 🤔 Jusqu’au 19e siècle, il n’y a pas d’heure légale en France.…
1 When accessing resources from my code, I sometimes need to specify the current bundle, but the existing API isn’t great. Here’s an alternative. Apps typically load resources via the Main Bundle ( Bundle.main ), but sometimes this is not what we want. For example, in plugins or frameworks, the code of the framework will need the bundle for that framework. Another example is with unit tests: I…
If you’re familiar with Cocoa developement, you probably know what UserDefaults are. Otherwise, a quick recap: (NS)UserDefaults is the macOS/iOS/tvOS name for “user preferences”. The NSUserDefaults API, while very powerful, has all the traits of Objective-C: it’s dynamic, weakly-typed, string-based, and quite verbose. Recently, two very good implementations of Type-Safe User Defaults have made the…
1 Raise your hand if you’re an Objective-C developer and you’re sick of writing this: if ([ obj respondsToSelector : @selector ( foo )]) { id foo = [ obj foo ]; } Unless you’ve switched to full-time Swift, in which case you can do this: let foo = obj . foo ?() I want that, but for Objective-C. id foo = [[ obj please ] foo ]; I had been thinking about doing this for years, but only actually tried…
This is the blogpost version of a talk at Cocoaheads Paris in December 2015 1 . TL;DR: 17-second video at the end. – A few months ago, Captain Train opened a dataset of train stations in Europe. Here are the train stations in Paris: Let’s zoom out to get a better view: Whoops. The UI stalls for a dozen of seconds, which isn’t entirely a surprise: the whole csv is 23,000 POIs 2 . Once we’re done…
Apple isn’t really famous for its contributions to open source projects: its latest major effort was Mac OS forge . As the name implies, it dates from when sourceforge was cool. On the other hand, Apple publishes the code ot the opensource components it uses at opensource.apple.com . I wrote a small script that scrapes the projects metadata, downloads all the tarballs and recreates git…
When I started working as a software engineer ten years ago, I was tasked to write the Mac version of an existing project, and I was to do it using Visual Studio, on Windows. As a matter of fact, the first decision I made was to pick a cross-platform development framework. Over the following years, I spent countless days trying to make cross-platform code look decent both on Windows and Mac OS. 1…
In the previous post I mentioned a code pattern frequently used in tests: Run the RunLoop until something specific happens. I’ve written and rewritten this method, making the same mistakes a few times. Here are two of the latest implementations I had ended up with: Variant A: - ( void ) runUntilBlock :( BOOL ( ^ )()) block timeout :( NSTimeInterval ) timeout { NSDate * endDate = [ NSDate…
Here’s a subject that’s rarely discussed amond developers, even though it’s one of the most important component of all apps: Run Loops . Run loops are like the beating heart of apps; they are what make your code actually run. The basic principle of a run loop, in fact, is quite simple. On iOS and OS X 1 , CFRunLoop implements the core mechanism used by all the higher-level messaging and…
English/TL;DR The rules of french punctuation require a thin space before some marks. However, there’s no easy way to insert a thin space, so most people just go with regular spaces. That’s a shame. Vous êtes sans doute déjà tombé sur ce genre de citation : Les « pains au chocolat » et les « chocolatines ». Qui sont-ils ? Quels sont leurs réseaux ? Un point pour l’effort : il y a des espaces avant…
A few weeks ago, I stumbled upon these private methods on NSObject : @interface NSObject ( Private ) - ( id ) _ivarDescription ; - ( id ) _shortMethodDescription ; - ( id ) _methodDescription ; @end They can be used to obtain debug descriptions of the passed objects: _shortMethodDescription lists all the instance and class methods of the receiver, _methodDescription does the same, including the…
I often write small tests programs in Objective-C, to experiment stuff or play with something. Most of the time, I put everything in the main.m file, and get rid of everything else: #!/usr/bin/env objc-run @import Foundation ; @implementation Hello : NSObject - ( void ) sayHelloTo : name { printf ( "Hello %s, my address is %p \n " , [ name UTF8String ], self ); } @end int main () { id hello = […
Great news Mac and iOS developers! You don’t have to upload screenshots manually to iTunes Connect anymore. There’s an Apple-provided tool to help you! It kinda sucks, but that’s OK. At least we can script it. iTMSTransporter stands for iTunes Music Store Transporter , which means it wasn’t made for you. Actually, I don’t think it was made for anyone ; my best guess is that it’s a byproduct of the…
The Objective-C collections classes from Foundation, NSArray , NSSet and NSOrderedSet , already support various forms of functional-style programming. First, and probably oldest, is: [ NSArray makeObjectPerformSelector :] Key-Value Coding has: [ NSArray valueForKey :]; and of course, there’s the block-based: [ NSArray enumerateObjectsUsingBlock :] Similar methods are available for NSSet and…
Yet another little objective-C hack, for when you just want to count: for ( NSNumber * num in [ @2 to : @4 ]) { // do something with num } Here, [@2 to:@4] is actually the same thing as @[@2, @3, @4] . Probably of little use, but very easy to write: all it takes is a method on NSNumber and a very small NSArray subclass. Here’s the one public method: @interface NSNumber ( ObjcRange ) // returns an…
A few months ago, I made this cool looking View Controller animation for my app Bicyclette . I was tired of the “Horizontal Flip” animation, and I wanted to clarify the distinction between the main (foreground) and accessory (background) 1 views. Here is an open-source, cleaned-up version of this Fan Deck View Controller . It is a Container View Controller , which makes it easy to use: Step 1:…
Here’s a little experiment I made last week. It’s an alternative syntax for Key-Value Coding , which is, as you may know, one of my favorite features of Objective-C. My quick hack lets you write stuff like this: // labels is an array of UILabels labels . kvc [ @"font" ] = aNiceFont ; instead of the usual syntax: [ labels setValue : aNiceFont forKey : @"font" ]; The idea is to use a Trampoline…
I recently had to debug a complex Responder Chain-related bug: Did you know that when you send a nil-targeted action message, but there’s no first responder, the chain is started from the sender of the message? It seems to make sense, but I can’t find mention of it in the documentation . 1 Anyway, I ended up writing a few utility methods to help me track this bug. Here they are: @interface UIView…
TL;DR: Don’t declare IBOutlets using @property (weak) anymore. Just use private ivars: ARC will take care of the rest. ## IBOutlets are, as the name implies, what links your Objective-C code to your nib files (“IB” stands for Interface Builder 1 ). It’s not a language keyword ( IBOutlet is actually defined as “nothing” for the compiler) Interface Builder uses them to find the connections that can…
Here’s an NSArray Category I’ve used in every single Cocoa project in the last seven years . 1 What it does is quite simple, and you can probably guess just by the method names: it lets you filter NSArrays with Key-Value Coding. @interface NSArray ( KeyValueFiltering ) - ( id ) firstObjectWithValue :( id ) value forKeyPath :( NSString * ) keypath ; - ( NSArray * ) filteredArrayWithValue :( id )…
I really, really suck at shell scripting. I don’t do it quite often, hopefully, but I’d like to write scripts in a more modern language. Of course, in the real world, I’m going to use Python or Ruby or anything that’s less insane than shell. However, the language I’m most comfortable with is Objective-C. Here’s a hack (don’t do this at home) to make your .m files directly runnable. 1 The idea is…
This week’s post is about a UI widget you’ve already seen dozens of time today: Please wait, I'm loading stuff. Everyone who’s used a computer in the last 20 years knows what this means. This is a “spinnnig loading indicator”, technically known as “ Indeterminate Progress Indicator ”. That’s opposed to a “Determinate Progress Indicator” (or a “Progress Bar”) : this UI item informs you there’s…
Even with the current trend of gesture-based interfaces, every app needs a button here and there. The UIKit class for buttons is called UIButton and it’s easy to customize with a background or an icon. In fact, nearly all iOS apps use customized buttons instead of using the native look. It’s not a surprise, given that the native style of UIButton , isn’t very appealing: This is…
Key-Value Coding is an Objective-C mechanism for introspection and (limited) Higher Order Messaging . If you don’t already know about it, you should read the documentation , NSHipster’s post about KVC Collection Operators , and “Let’s build Key-Value Coding” by Mike Ash. While KVC is already really powerful, its implementation hides some really nice (and undocumented) details. The Basics — KVC 101…
The best app for Vélib is growing bigger! Bicyclette 2 is almost ready, and it needs your help! Register for the beta here . It now works with 50+ Bike-Sharing Systems in the world , including Paris, Lyon, Bordeaux, Strasbourg, Nice, Lille, Barcelona, Dublin, Brussels, Wien, Montréal, Toronto, Washington, Melbourne… Also new in 2.0 : the favorites system has been totally reworked. Instead of…
In iOS apps, we write Custom Views all the time. For example, CocoaControls has a nice collection of custom views. However, it’s sometimes a tedious task: you typically have to implement drawRect: or build your view contents by hand, using -addSubview: repeatedly and setting UI properties in code. Not beautiful. label = [[ UILabel alloc ] init ]; label . font = [ UIFont boldSystemFontOfSize : 15 .…
When coming from another language, strings in Objective-C are surprising on one aspect : objects of the string class, NSString are immutable : their value cannot be changed. Objective-C also has Constant Strings . As C does with string literals, Objective-C embeds, in the binary, objects of the NSString class. Of course, Constant Strings are Immutable. Let’s look at some of the surprising details…
I like that name, don’t you? bou.io There’s a ton of subjects I want to write about, so hopefully this will not stay empty too long. This blog is entirely static, (except for google analytics). It’s written in markdown , using Jekyll hosted on GitHub Pages .