Archive for March 16, 2013

Saturday, March 16, 2013 [Tweets] [Favorites]

Lazy Evaluation and Streaming With NSFastEnumeration

Rob Rix:

Since Wolf and Michael’s posts, the old RXMap that took a second argument as the collection to fold the mapped results into is gone. In its place is an RXMap which returns an object conforming to NSFastEnumeration instead of an instance of a collection class. RXMap is dead; long live RXMap!

[…]

The latter two benefits can be summed up as lazy evaluation and streaming. Enumerating a long chain of maps with a for(in) loop will only take as much CPU time and memory as is required for each stage to complete, and the results will be processed as soon as they’re available, rather than waiting for each stage to complete before going on to the next. All this without threads or asynchrony!

It’s tricky to get NSFastEnumeration right, especially with ARC, but his framework hides much of the messiness—and it sounds like a future version will hide more.

Console Messages With Keys and Hashtags

Apple (via Peter Hosey):

You are also encouraged to include hashtags in your log messages, regardless of what API you use. A hashtag is composed of a hash (#) symbol, followed by at least four non-whitespace characters, terminated by whitespace or the end of the message. Hashtags may not begin with a number. Additionally, any custom ASL key that begins with a hash is treated as a hashtag. The Console application and the logging APIs understand hashtags on OS X v10.6 and later.

Google and CalDAV and CardDAV

Clark Goble:

Lost in all the hue and cry over Google, as long expected, killing Google Reader were its other products being ended. The most significant to my eyes was Google dropping CalDAV support and requiring all clients to use their Calendar API. If you subscribe to any Google Calendars via Apple’s Calendar you’ll note that while it has a separate Google menu all subscriptions are via CalDAV.

He also wonders about the future of CardDAV at Google and recommends Contacts Sync as a better way of syncing your Apple and Google contacts than the built-in support in Mac OS X. This might also be a good way to get your contacts database into Google Maps for iPhone.

Update (2013-03-18): Clark Goble:

Google updated that page about other products being end of lifed. Apparently they are now backing off dropping CalDAV. We’ll see what that means.

Google:

We worked with the developers who provide 98 percent of our current CalDAV traffic to assure access to the CalDAV API, which means many popular products will not be impacted. We remain committed to supporting open protocols like CalDAV.

Update (2013-06-06): Chris Welch (via Jordan Merrick):

In a reverse of course, Google just announced that it will be keeping its CalDAV API open to all developers. Additionally, the company is today making CardDAV — its preferred tool for syncing contact information — available to the public for the first time.

Shebang Objective-C

Nicolas Bouilleaud has a clever trick for making Objective-C source files self-compiling (via Romain Briche):

The idea is to play with shell and C comments so that the file is both a valid shell script and an Objective-C program. The shell script calls clang to compile itself, and then runs the output executable.

I’ve fixed the quoting so that it also works when the path contains a space:

/*/../bin/ls > /dev/null
COMPILED="${0%.*}"
clang "$0" -o "$COMPILED" -framework Foundation;
"$COMPILED"; rm "$COMPILED"; exit;
*/

#import <Foundation/Foundation.h>
  
int main(int argc, char *argv[])
{
    @autoreleasepool
    {
        NSLog(@"Hello %@",NSProcessInfo.processInfo.environment[@"USER"]);
    }
    return 0;
}

Make the .m file executable and you can run it from Terminal. Unfortunately, it won’t run from BBEdit’s #! menu because the file doesn’t actually begin with #!.

NSURL Cannot Handle Unicode Strings

I was just reminded of this bug that Craig Hockenberry reported over four years ago. The regular method for creating a NSURL is overly strict, so I’ve long been creating them via a category method. I need to modify it to handle Unicode in the domain, too.

Update (2013-03-18): A -[NSURL isEqual:] bug from Tim Wood:

NSURL should compare the decoded paths, not the encoded paths so that the %5b vs %5B case difference doesn’t spuriously make these URLs seem different.

Xcode 4.6.1

Xcode 4.6.1 fixes the bug introduced in 4.6 in January that caused all applications that use ARC to crash at launch when run on Mac OS X 10.6.