Archive for March 2013

Sunday, March 31, 2013

Universal Procedure Pointers

Uli Kusterer:

A UPP was a simple data structure that described the calling conventions and location of a PowerPC function in RAM, and started with a 68000 instruction. This data structure could be handed to any system function where it expected a callback, and could be executed by 68000 code just like a function pointer.

[…]

But of course the Intel CPU didn’t have that [endian] switch. And since an emulator only knows about raw bytes, the PowerPC emulator (“Rosetta”) in Intel Macs could not transparently convert the stored bytes. So it was decided to not allow mixing of PowerPC or Intel code at all. There would only be a tiny bit of translation at the point when a PowerPC application called into the system.

Hotline Revisited

Benj Edwards:

At the height of Hotline’s popularity in the late 1990s, users could connect to thousands of Hotline servers that suited every imaginable user interest. Many of them catered to underground tastes, providing pornography, MP3s, and warez (pirated software) with almost free reign, which attracted the lion’s share of media attention during Hotline’s heyday. But beneath the sensational headlines, strong communities formed through Hotline that led to lifelong friendships and emotional support groups.

10 Things You Need to Know About Cocoa Autolayout

Ole Begemann:

Unfortunately, using autolayout with Interface Builder forces you to be careful. For instance, if you find that you need to replace one control with another, deleting the original from your layout can lead IB to automatically create a bunch of new constraints that you then need to modify manually (again) once you have inserted the replacement control. It is probably not a good idea to constantly try to optimize your constraints while your layout is still in a state of flux. Better do it at a later stage when it is more stable.

Wil Shipley:

Constraints: The coolest technology in 10.7 masked by the WORST interface editor ever inflicted on humans.

Algolia

Algolia is a closed-source indexing and search engine for multiple platforms, with an Objective-C API. Apparently it’s faster and more efficient than Search Kit, which has languished and is not available for iOS.

Low-Cost iPhone

Pierre Lebeaupin:

But I think the most important reason is that having dedicated base models would allow Apple to sell devices where the hardware design flaws of yesterday (visible or invisible) are fixed, instead of having to keep having to take them into account in the next X years of software updates.

I recently came across a guy who was lamenting that he had just bought an iPhone 4. He had heard of Antennagate but thought Apple had fixed the problem. Yet, almost three years later, the iPhone 4 is still shipping with the same flawed antenna design. He’d spent the past week visiting a major US city, where his friend’s iPhone 4S consistently had better coverage on the same network.

Periodically I hear about cheap Android phones, and I’m about to chime in that there’s a “free” iPhone model, too. Then I remember my own horrible experience with the 4. I can’t believe Apple is still selling it.

Saturday, March 30, 2013

Debug It!

Mark Bernstein:

There are two kinds of tricky bugs. The first is the masquerade party: something is going wrong, it’s clear what the problem is, but that can’t happen.

[…]

One of the great contributions of Martin Fowler’s Refactoring was that it gave a name to one of the best approaches to addressing an intractable bug. If you can’t find the problem, and localization strategies can’t quite pin it down, you can just refactor the hell out of the neighborhood. This may or may not fix the bug, but at least it improves the code. Before refactoring, bug hunts left tracks all over the program in the form of hooks and temporaries and diagnostic writes. Nowadays, bug hunts leave mown lawns and cleaner design.

I also found Debug It! to be a good basic level book. I’m not aware of any good advanced books on this topic. This seems to be the case for most areas of our field.

iCloud and Core Data

Ellis Hamburger:

“Many of these issues take hours to resolve and some can permanently corrupt your account,” one top developer told me. “AppleCare has been unable to assist our customers who run into these issues.”

[…]

Many veteran developers have learned their lesson and given up on iCloud’s Core Data syncing entirely. “Ultimately, when we looked at iCloud + Core Data for [our app], it was a total no-go as nothing would have worked,” said one best-selling iPhone and Mac developer. “Some issues with iCloud Core Data are theoretically unsolvable (stemming from the fact that you’ve put an object model on top of a distributed data store) and others are just plain bugs in the implementation,” he said.

[…]

WWDC 2013 is just around the corner, and while many of iCloud’s syncing issues have been fixed, dozens of bugs remain unsquashed. So can these issues ever be solved? “[Apple’s] approach to the problem was very novel and interesting, and perhaps they will ship a version of it that works – but it functions very differently than typical sync solutions in that there is not a central server hub that maintains the ‘truth in the cloud,’” Pierce told me. “Because of this there is a lot of fragility to the implementation, and I’m not sure it will ever scale well to larger data sets,” he said.

Josh Centers:

The article insinuates that Apple doesn’t care enough to fix the problem. I don’t think that’s the case. Rather, I don’t think they know how to fix the problem. They aimed high, but ultimately bit off more than they can chew.

Jacqui Cheng:

Opaque errors are just the beginning—developers are also frustrated with how iCloud handles a user’s data if the user chooses to turn off document and data syncing. Doing this, it turns out, completely removes a user’s locally stored iCloud data. And signing out of iCloud results in the system moving iCloud data outside of an application’s sandbox container, making it impossible for the app to use the data any longer. The assumption here is clear: you’re either using iCloud exclusively for data storage or you don’t want to use that data at all.

Matthew Panzarino:

So when I say that there are two iClouds, I mean that there are two iClouds. One of them is used heavily inside Cupertino for its own services and the other is offered as a developer API and used only selectively for Apple’s own apps. I’m not here to say whether that’s right or wrong or fair or not or whatever, those are just the facts.

And, once you dig in, iCloud for developers is far less a completely holistic solution and much more of a loose bundle of networking protocols and systems that are unified in name only. It involves so many departments and teams inside Apple that it makes for a very fragile system.

Rich Siegel:

In general, when iCloud data doesn’t synchronize correctly (and this happens, in practice, often), neither the developer nor the user has any idea why.

[…]

In some circumstances (and we haven’t been able to figure out which, yet), iCloud actually changes the object class of an item when synchronizing it.

[…]

In some cases (again, not all the time), iCloud may do one of the following:

  1. Owner relationships in an item’s data will point to the wrong owner;

  2. Owner items get lost in synchronization and never appear on computers other than the one on which they were created. (This leads to the item never appearing in the UI on any other machine.) When this happens, bogus relationships get created between blob items and an arbitrary unrelated owner.

[…]

When the blob data doesn’t show up, we have no choice but to wait — the application can’t display what isn’t there, and there are no mechanics by which Core Data can make a request for immediate delivery of the data from iCloud.

Justin Williams:

Core Data’s iCloud gets most of the grief when it comes to the public perception of the troubles, but document sync isn’t all oats and honey. I have had a nearly complete version of Elements ready to ship with iCloud support for several months. Why do I say nearly complete? There are bugs related to iCloud’s document syncing architecture that make me extremely uncomfortable shipping the software.

There’s also a good thread on Hacker News:

No one really fully knows WTF is going with iCloud - documentation is basically nonexistent, support unavailable, implementation broken in trivial ways, and error messages inscrutable. […]

IMO, from having studied this for many, many hours over many moons, is that what Apple is trying to do is fundamentally hard, if not entirely unfeasible. They’re trying to replace a smart server with one that’s dumb as a doorstop. More specifically, they’re trying to emulate a CRUD web service with a file sync engine.

Conflict resolution is left up to individual clients, since the server doesn’t do any “thinking”. Likewise, there is no canonical, authoritative state of the store, since the server doesn’t “think”, only the clients do. Apple was hoping that by shoving a bunch of diffs of your database onto the server, that clients can reliably reconstruct a sane database by playing them back - except that multiple clients are updating the diffs simultaneously and there is no server-side conflict resolution.

Oh, and if stuff fails, there are no regular snapshot states to fall back to, because iCloud is a file store, not a database engine. Your whole store is now corrupt. Enjoy.

Oh, and there’s no way to nuke the database and start over - there are metadata files that are undocumented or that we don’t even have sandbox access to, that interfere with completely destroying the database.

Update (2013-03-31): Another Hacker News thread:

It is trivially easy for a combination of devices (or really, just two) to generate a combination of diffs that do not playback to a consistent database state.

In a normal world where CRUD operations are handled by a server with some understanding of the underlying data model, the server resolves conflicts as the authoritative data source, and thus consistency is maintained.

In the world of CDIS, there is no authoritative server, nor is one device ever designated as the canonical state (this would be unrealistic, since devices get retired and lost, nor is there anything special about a device that makes it canonical). Instead, conflict resolution is left to each device, the implementation of which is broken. Which is to say, your CDIS-enabled database will work fine until the moment two devices make conflicting changes. At which point it is irrecoverably corrupted.

The CDIS client’s reaction to this is to revert your local copy of the database to its last known good state and cease communicating with iCloud entirely. This error occurs silently without either notification via UI (to the user) or API (to the developer). There is no way to query this state, and as of today the only visibility into this error is via console logging.

Update (2013-04-03): Tom Harrington:

One day you call -addPersistentStoreWithType:configuration:URL:options:error: and it fails, with an incomprehensible error about not being able to upload (or sometimes download) a file named baseline.zip. Or else, some other equally incomprehensible error relating to undocumented internal classes like PFUbiquityImportScanOperation or PFUbiquitySwitchboardCacheWrapper. You’ve never heard of baseline.zip, and you weren’t attempting to upload or download anything. Your app doesn’t have access to iCloud at this point, but what’s worse, you also don’t have access to your local data store, and you have no recovery path for either problem. Worst of all, you did not actually do anything wrong, and there’s nothing you can do to fix it. Try again, and better luck next time.

Update (2013-04-11): Tom Harrington:

Today I’m starting off with some things that, while not actually bugs, may catch a developer off guard. In this post I’m sticking to how iCloud is designed to work, and not getting into the questions of how and when it doesn’t work.

Update (2013-04-16): Tom Harrington:

When iCloud has new incoming data, it imports the new changes to your data store first and tells you about them afterward. You find out about this when NSPersistentStoreDidImportUbiquitousContentChangesNotification gets posted. There is no corresponding will import notification or anything like a should import delegate call that might allow you to veto changes. And since Core Data doesn’t care if you create a duplicate, duplicates are created and you’re left to clean up the mess.

Update (2013-05-07): Tom Harrington:

The upshot? I’ve seen addPersistentStoreWithType:etcetera: block for 30 minutes. And keep in mind, this is when iCloud is working normally. This is not an error condition, this is “working as designed”.

Brent Simmons:

Even if Apple works out syncing — somehow — that’s just not enough. That just gets us to where we should have been in 2008. The future belongs to apps with more sophisticated services.

Update (2013-05-15): Tom Harrington:

Neither of them turns out to be very interesting. Trailers has two entities and the spelling dictionary just one. Neither has any relationships. But this lack of interesting detail is, really, the interesting part. In the only two examples I’ve been able to find of Apple using iCloud with Core Data, the data models are almost trivial. Less complex, in fact, than you’d expect in a decent introduction to using Core Data.

Update (2013-05-23): Drew McCormack:

With WWDC just around the corner, we again start to ponder if this will be the year Apple gets iCloud right. But the more I dig into iCloud/Core Data sync, the more I have come to realize that even if it worked as designed, it still may be quite flawed as a solution. They may have gotten it wrong from the outset, and some design failures are probably not easily addressed. What follows is a list of what I think is fundamentally wrong with iCloud/Core Data’s design, leaving aside any of the practical failures that we have witnessed in the past.

Update (2016-06-17): Here are some more posts that I’ve written related to iCloud Core Data:

Thursday, March 28, 2013

appscript on GitHub

Matt Neuburg (via Clark Goble):

Hamish has made it very clear that he isn’t willing to touch this code any further. So it seems obligatory that someone else should put it in a place and form where people can fork it and continue to maintain it. Here it is, then.

There’s no reason in the world, for example, why appscript should stop working just because Hamish insists on using ascr/gdte as a way of fetching an application’s dictionary. There are many other ways to fetch the dictionary that work perfectly well with appscript. The next step, clearly, will be to commit some of those into this repository.

TextEdit 1.8 Source Code

Apple has posted the source for TextEdit, which used to be available as part of the Xcode installer (via Zach Drayer). I miss the days when you could do a local search of all the sample code and documentation. Now, everything is scattered online, where it’s harder to search and subject to removal.

Regular Expression to Match Multiples of 3

Alok Menghrajani (via Nicolas Seriot):

An easier way to solve the problem requires understanding that regular expressions can be written as finite state machines, and vice versa. […] The state machine is going to process the input and keep track of the sum of the digits. We only need the sum modulo 3, so we’ll have a pretty simple state machine with 3 states: state A (starting state), state B (we are off by 1), state C (we are off by 2).

Core Text and Upper Case Numbers

Amy Worrall:

The reason I’m currently looking at number case is because I’m implementing an unread badge in an iOS app. I need to put a number centred in a circle, and our designer has given me the font to use. It turns out the font (Raleway, one of the Google fonts) defaults to lower case numbers, which makes centring them hard.

Thursday, March 21, 2013

Two-Step Verification for Apple ID

Apple HT5570:

Your Apple ID is the key to many important things you do with Apple, such as purchasing from the iTunes and App Stores, keeping personal information up-to-date across your devices with iCloud, and locating, locking, or wiping your devices. Two-step verification is a feature you can use to keep your Apple ID as secure as possible.

This is much better than asking for a device serial number and should help against Mat Honan–type social engineering.

If you no longer have access to one of your devices, go to My Apple ID to remove that device from your list of trusted devices as soon as possible so that it can no longer be used to help verify your identity.

Of note, it does not appear that two-step verification is needed to remote wipe or to access FileVault-encrypted files on a locked but powered-on Mac. It seems more likely that someone would get my Apple ID password than that I would need to remote wipe or would forget my Mac’s password, so I don’t have Find My iPhone or login password recovery enabled. I wish there were a way to enable Find My iPhone without enabling remote wipe.

Update (2013-03-21): Rui Carmo:

I am clearly in the minority that thinks of two-factor auth in and by itself as security voodoo to appease the unwashed masses — especially if you don’t follow it up with privilege separation — and I’m going to stick to my guns on this one.

I’d also like to note that if you have a non-phone, you don’t have SMS, and so in order to use two-factor authentication you must enable Find My iPhone and its remote wipe feature.

Update (2013-03-22): Chris Welch (via Jordan Merrick):

Unfortunately, today a new exploit has been discovered that affects all customers who haven’t yet enabled the new feature. It allows anyone with your email address and date of birth to reset your password — using Apple’s own tools.

Update (2013-05-31): Dan Goodin quotes Vladimir Katalov:

“To me the story here is all about Apple offering a 2FA [two-factor authentication] solution that doesn’t really add much extra security for you (files, documents etc), but it protects them (and you) from unauthorized money transactions and changes to your account,” Per Thorsheim, a security consultant in Oslo, Norway, wrote in an e-mail to Ars. “People are not made aware of this at all, and it will be a false layer of security when people enable 2FA and put sensitive and secret documents into iCloud.”

Glenn Fleishman:

Apple has suffered enough security stumbles in the last few years that it shouldn’t lag in this regard. It has been behind the curve many times in ways that damage customers’ identities, online integrity, and safety. Apple needs to use its engineering prowess to solve this problem and solve it quickly. Google already has for its users.

“Send to Kindle” Button

Amazon:

Have you ever encountered news, blogs, articles and other content on the web that you want to read but don’t have time to do so immediately? The Send to Kindle Button lets you easily send that content to your Kindle to read later, at your convenience. Just send once and read everywhere on any of your Kindle devices or free Kindle reading apps for iPhone, iPad and Android phones or tablets. No more hunting around for that website or blog that caught your eye—just open your Kindle and all the content you sent is right there.

Good idea, but it’s plug-in based and doesn’t work in Safari. Why couldn’t they just use a bookmarklet like Instapaper?

The Return of NetNewsWire

Daniel Pasco:

As far as sync is concerned, we knew we would likely need an alternative to Google Reader as early as last year. At the time, the option that seemed to make the most sense was to embrace iCloud and Core Data as the new sync solution of choice. We spent a considerable amount of time on this effort, but iCloud and Core Data syncing had issues that we simply could not resolve.

It’s good to hear that they’re trying a new strategy that’s more under their control. And it’s unfortunate that iCloud has held back updates, even though not all NetNewsWire users need syncing.

Update (2013-03-30): Brent Simmons:

If you’re writing an RSS reader, you can’t ask iCloud to download feeds.

iCloud can’t poll Twitter to see if your follower count has gone up or down. iCloud can’t generate weather forecasts. iCloud can’t track ships.

There are all kinds of services that make sense on the server side. You could do some of them on a client, but at the expense of timeliness and battery life. If it’s a good idea, and you don’t do it on a server, your competition just has to write a server that does it, and your app is finished.

JSErrorStackTrace

Javier Soto’s JSErrorStackTrace is a “category on NSError that stores the stack trace of the creation of the NSError object for later retrieval” (via Romain Briche). It’s very useful to have this attached to an error object. He swizzles the initializer and gets the stack trace using -[NSThread callStackSymbols]. That method wasn’t available when I wrote my code, which adds stack frames to the error’s user info as it’s propagated.

Tuesday, March 19, 2013

PDFpen 6

PDFpen 6 is now available. Here’s an overview of what it offers compared with Preview (which still isn’t AppleScriptable). I frequently use PDFpen to OCR scanned documents in EagleFiler.

One of the interesting new features is the ability to convert a PDF to Microsoft Word format. This is done via the Nuance OmniPage Cloud Service, which works amazingly well. Conversion from PDF format is not my first choice of workflow, but it’s good to know that it’s possible in a pinch.

The direct sale version of PDFpen 5.7 could access iCloud via the PDFpen Cloud Access app. This helper app is no longer available, so iCloud support is now available only if you purchased PDFpen from the Mac App Store.

Update (2013-03-19): Adam C. Engst looks at PDFpen in more detail.

iOS 6.1.3

Jacqui Cheng:

More than a month after security researchers pointed out a new passcode bug in iOS, Apple has patched it with the release of iOS 6.1.3. The software update, released over the air or via iTunes, is mainly aimed at addressing the security vulnerability that allowed attackers to get around an iOS device’s passcode by performing a series of steps.

Bugs happen, but it seems like there must be something wrong with the design to enable so many lock screen bugs. This is different from all the iPhone alarm bugs, where it seems like a lack of testing is to blame.

Monday, March 18, 2013

Core Data Auto Migration and Sandboxing

P. Taylor Goetz:

Core Data Automatic Migration for NSPersistentDocument requires saving in place, which won’t work in a sandbox-enabled app (even with Read/Write for user selected files).

This is like the more well-known issue with Core Data and SQLite journal files, except that the filename suffix isn’t predictable. Behind the scenes, Core Data tries to create a file with .migrationdestination_ and a long hex string, and the sandbox denies it. This is not some crazy edge case—it’s the default behavior of Cocoa’s basic class for Core Data documents.

A workaround is to put the database file in a package, but this is not always possible. And, in fact, NSPersistentDocument does not support packages.

How to Build an RSS Sync System via App.net

Jens Alfke:

Google pulled the plug on Reader, but you still want a way to keep the news-reader apps on your various devices in sync, so they all know what feeds you’re subscribed to and which articles you’ve already read.

Here’s what you do. I’ve built this before, as part of the OS X Syndication and PubSub frameworks. (It wasn’t identical to what I’m describing here, partly because app.net didn’t exist so I had to do some clever things with hidden file storage on mac.com. Aren’t you lucky?)

What Lua Scripting Means for Wikimedia and Open Source

Sumana Harihareswara (via Gus Mueller):

So our staffers and volunteers worked on Scribunto (from the Latin for “they shall write”), a MediaWiki extension to allow editors to embed Lua scripts instead of wikitext for templating. And volunteers and Foundation staffers have already started identifying pages that are slow to render and converting the most inefficient templates. We have 488,731 templates on English Wikipedia alone right now. The process of turning many of those into Lua scripts is going to affect everyone who reads our sites — and the Scribunto project has already started giving back to the Lua community.

Safari Still Craps Out Too Frequently

Erik Barzeski:

Seriously, it’s 2013. I have 32 GB of RAM. And Safari still craps out all the time and has to reload every page I’ve loaded with as few as 20 tabs open.

Ever since the Safari Web Content process was split off in Lion and sandboxed (the Safari application remains unsandboxed), I’ve been getting into situations where pages stop responding until I quit and relaunch Safari.

Wolf’s Mother Tries an iPhone

Jonathan Rentzsch:

She mentioned the Clock is wrong. She thought it odd since the other, textual clocks were correct (the first on the Slide to Unlock screen and the uppermost status bar clock). The Calendar app’s date is correct, so she has no reason to believe that the Clock’s icon just happens to be static.

[…]

In the same vein, she noted the Weather app must be showing the inside temperature (72°) since it’s currently in the mid-30°s outside when she was looking at it.

[…]

She was immediately thwarted when tapping a headline link opened the page in a new tab. Her Google News page was pushed away and the Los Angeles Times’ page came frontmost. Because it was a new page, the back button wasn’t enabled. She was at a loss at how to go back, not noticing the nondescript tabs button that held the key to her return.

Stupid Feed Tricks

Brent Simmons:

Brian is intimately acquainted with the the different ways feeds can be screwed up. So he posted Stupid Feed Tricks on Google Docs.

The difference between theory and practice…

Update (2013-03-18): Brent’s favorite way to screw up a feed.

Checkboxes That Kill Your Product

Alex Limi:

In the currently shipping version, Firefox ships with many options that will render the browser unusable to most people, right in the main settings UI.

[…]

What I do want to put the focus on, however, is that you have to perform an audit of your product every so often and see how the people using your product have changed, and what kind of functionality that made sense at the time may not make much sense anymore.

Improving Download Behaviors in Web Browsers

Alex Limi (March 2010):

The aim of this article is to give an introduction to how the most common browsers behave when it comes to downloading files, what opportunities exist, and close with a set of recommendations for how to fix this in Firefox and other browsers. It is my hope that putting these ideas out there will spur some innovation in this area both in Firefox and competing browsers.

Alex Limi (May 2011):

Today, I was very happy to see that Safari has implemented our design in their upcoming release, as evidenced by screenshots posted at Dustin Curtis’ site […]

However, as of Firefox 19.0.2, the Downloads window seems much the same. And, on my Mac, there’s a bug where the Clear List button is always disabled, which drives me crazy. Here’s the plan for Firefox 20.

Sunday, March 17, 2013

Google Reader Over and Out

Brent Simmons:

I think this is a good thing for RSS and RSS readers in general — but it’s sure going to hurt RSS reader customers unless people come up with a sync solution quickly.

Although, personally, I haven’t felt much need for RSS syncing.

Update (2013-03-18): Brent Simmons:

I created a new mailing list for people who want to talk about the technical side of RSS syncing.

Saturday, March 16, 2013

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.

Friday, March 15, 2013

Deploymate 1.0

Xcode used to let you target an older version of Mac OS X by configuring your project to use that OS’s SDK. For example, you could develop on 10.6 while deploying for 10.4. If you used any APIs that were not available in 10.4, Xcode would report a compilation error. Recent versions of Xcode have essentially removed this functionality because Xcode now only supports the SDK for the previous version of the operating system. For example, Mac OS X 10.8 is the current version, so Xcode only includes an SDK for 10.7. Too bad if you want to target 10.6. And, presumably, Xcode will soon ship with support for pre-release versions of 10.9, dropping SDK support for 10.7.

Apple engineers like to point out that Xcode still lets you set the deployment target to older versions such as 10.6, but in practice this is error-prone because Xcode will never tell you when you are using an API that isn’t available on that version. You won’t find out until you run the app on the older OS and actually exercise the code path that calls the API. Then it will crash.

Deploymate promises to solve this problem (via Matt Drance). It can analyze an Xcode project and tell you whether you’re calling APIs that are not available. Unfortunately, there is currently no way to tell it to ignore calls where you know what you’re doing, e.g. if you’ve conditionalized the call. It may be possible to outsmart its analysis in such cases, however. Even with this limitation, Deploymate looks to be an invaluable addition to my toolkit.

The developer tried to make Deploymate available via the Mac App Store but was thwarted by sandbox issues.

Update (2013-05-05): Jeff Johnson shows how to do something similar with a prefix header.

Thursday, March 14, 2013

Kiln Harmony

Joel Spolsky:

One of the biggest new features is Kiln Harmony, which lets you operate on Kiln repositories using either Git or Mercurial. So you can push changes to a Kiln repo using Git and then pull them using Mercurial. This means that you never have to decide whether you want to use Git or Mercurial. Religious war: averted.

Benjamin Pollack:

There’s a lot of magic that goes into Kiln Harmony. Rather than try to cram all that material into a little blog-post, we’ll be running a series of articles in the coming days on how Kiln Harmony works. We’ll take you under the covers into the details of our implementation, how we handle bizarre corner-cases, how we handle data formats that are more defined by their violations than their nominal structure, and more.

Benjamin Pollack:

Kiln Harmony had three iron requirements: it had to be repeatable (you couldn’t get different repos on subsequent translation attempts), lossless (we couldn’t discard data just because it was hard to preserve), and idempotent (a given Git commit or Mercurial changeset had to always generate exactly the same counterpart for a given repository, with no exceptions—even across Kiln installations or with a side-trip through a site like GitHub or Google Code). This suggested to us a pretty straightforward architecture: every single repository would be stored both as Git and Mercurial on-disk, and we would write a daemon that synchronized changes between the two repositories.

Though I’m a happy FogBugz customer, I had previously ignored Kiln since I use Git. Now I’m wondering whether it would be helpful for me.

Update (2013-03-16): Benjamin Pollack:

We heard you, so beginning in Kiln Harmony, we’ll start looking through changesets, code, and file names, beginning the second you start typing. Not only does this get you the results you want faster; the feedback you get as you type helps you figure out what you’re looking for in the first place. On the Kiln team, we’ve found instant searches so useful that we barely ever go to the “real” results page, and we bet you will, too.

The Future of Software Pricing

Kevin Hoctor:

I think everyone can agree that we won’t survive long as indie developers if we can only charge one or two dollars for our apps. I don’t even think $15 is enough unless you have an enormous audience. So what do we do? How do we compete with the “race to the bottom” inspired by the App Store? I don’t have all the answers, but I do have my opinions and I’m willing to back them up with evidence through my business actions.

The $50 Mac version of MoneyWell seemed like bargain to me after using QuickBooks. I’m not interested in the iOS version, but having one free bank account with an in-app purchase for more seems like a good idea.

Booting Your Mac from a Duplicate

Joe Kissell:

In general, there’s no harm, and considerable benefit, in letting backups run. Your backup software should act as though your duplicate is your regular startup disk and keep copying files to its normal destination as though you had restarted normally. That’s probably what you want, because if you create or modify a file while running from the duplicate, it can then be backed up.

Perhaps it has since been fixed, but I’ve seen cases where this didn’t work right. Time Machine saw the duplicate as a new drive. Thus, rather than creating an incremental backup, it wanted to make a fresh copy of all the files. The only way to do this was to free up space by deleting the backups of the original drive. And the same problem happened again when switching from duplicate back to the regular startup disk. If you boot your Mac from a clone, I think it’s advisable to give it a different drive to use for Time Machine.

Presenting BlockAssert

Steven Fisher:

For various reasons, you sometimes can’t use NSAssert in a block easily. I’m going to explain why and describe a new macro, BlockAssert, which solves this.

MVVM and View Models

Colin Wheeler:

In the MVVM pattern the View Model encapsulates data/properties that the view can bind to, any validation logic and actions that can be performed. For instance if you had a button that needs to change its title text you would have a property on the view model that the button can bind its title property to. The same goes if you need to change the color of a control or enable and disable the control. In this pattern we are essentially taking the state of our app and putting it into a view model.

Among other benefits, this decoupling makes it easier to test and revise the interface.

Re-Downloading Mac App Store Apps

Peter Maurer and Jason Sims report that it is no longer possible to redownload one’s purchases if an app has been removed from sale. As Maurer says:

Looks like Apple fixed a bug that was actually a feature.

Mark Munz wonders what this means for upgrades, e.g. to iLife/iWork. If the new version is a free update, which the Mac App Store sees as the same product, people with older OS versions will not be able to download the old version. But, with this change, the old version will become inaccessible even if the new version is a new product.

Because the Mac App Store doesn’t let you go back to a previous version, even if the new version has a bug, I’ve been saving each app update that I download. I have a DropDMG configuration called “Mac App Store” that compresses the app, puts its version number in the filename, and saves it in my archives folder.

Forcing Aperture to Locate Referenced Files

Thomas Boyd:

Notice the “Reconnect All” button is not lit up even though the corresponding photo has been located. Hold down the Option key and the button will light up.

How Much, or How Little, I Use Interface Builder These Days

Brent Simmons:

Any one of those would be enough: all three thoroughly convince me to stay away from IB for all but the rarest cases.

And the fourth reason I added just yesterday is that dealing with auto layout in IB is not worth the hassle — not when it’s so much easier done in code.

I basically agree that Interface Builder is a beautiful idea that never really lived up to its promise. For a long time, I’ve been making small tweaks in code since it’s so much easier than modifying xib files (especially when localization is involved). And I’ve even run into bugs caused by IB incorrectly generating the xib. I hope to phase out IB as I transition to using auto layout.

Scrivener and the Mac App Store

Keith Blount on a one-character bug and the difficulty of deploying the fix to the Mac App Store:

Well, the trouble is that, as a developer, I have no way of testing the installation of the Mac App Store version across platforms. I can test the integrity of the installer package that I send to Apple (which I did), but not the full installation procedure. (If you are a developer and know this to be incorrect, please let me know. I can test the installer package on the 10.8 machine I create it with, but not on my 10.6 machine it seems.) And unfortunately, it seems that the Apple review process doesn’t test the installation procedure thoroughly, either, since this problem was not picked up by the App Review process. Thus Scrivener 2.4 went live with the problem.

[…]

But older versions don’t only become inaccessible to the user – they become inaccessible to the developer, too. Once I became aware of the issue and uploaded the 2.4.1 fix, I then looked for a way to revert the on-sale version to 2.3.1 until 2.4.1 got through review, so that this issue could be eradicated in the meantime. However, it seems there is no way of doing this, and that the only way forward is to wait for Apple to approve the 2.4.1 update.

Since the version in the store has a bug, and Apple won’t accept the fix, he’s temporarily removed the app from the store:

2.4 was released on the App Store last Thursday night, after a week in the review queue. On Friday morning, as soon as I found out about the bug in 10.6′s receipt validation code, I submitted a bug fix, Scrivener 2.4.1, to Apple, and I asked for an expedited review.

[…]

It is nearly a week now since 2.4 became available, and we still do not know when 2.4.1 will pass review and be made available on the store. 2.4.1 was rejected on Monday night for a reason that didn’t make sense (the reviewer said it wasn’t sandboxed when it was). We followed this up and resubmitted, but were then told that the reviewers needed more time. Yesterday, I was informed that they want us to make some changes to Scrivener 2.4.1 before it can pass review. I was also informed that Scrivener 2.4, 2.3.1 and 2.3 should really have not passed review either, given the things they want us to change. (Please note that the things we have been asked to change are not bugs, but features Apple interpret as not meeting their App Store review requirements.)

[…]

Incidentally, because of some of the changes we are being required to make, we cannot guarantee that Scrivener on the Mac App Store will have as good support for .docx, .doc and .odt formats in 2.4.1 and future releases. This does not affect the version on our site.

Do You Need a Third-Party Disk Utility?

Joe Kissell:

Lately I’ve noticed something curious: While I used to turn to such utilities every few months, I haven’t had to do so in a long time—certainly not in the past couple of years. Anecdotal evidence suggests that I’m not alone in this; disk errors beyond the purview of Disk Utility seem to have declined sharply.

John C. Welch:

So I think a huge reason why people don't worry about dedicated disk utilities anymore is that backing up has become such a literally thoughtless process, a hard drive crash is no longer the horrifying event it used to be.

I used to swear by DiskWarrior, but it’s now been a long time since I’ve used it. I used to run it periodically to optimize my volume’s catalogs, which really did speed things up, and several times it saved drives that had become completely unusable. Nowadays, I can imagine using it to get at very recently modified files if my drive became inaccessible, but I would no longer plan on resuming use of the repaired drive. Instead, I would erase it (or replace it) and restore from a SuperDuper! clone.

Fragmentation can still be a problem for large files such as an Aperture database or Spotlight index, which can accumulate thousands of fragments. SSDs reduce the effects of fragmentation, but I still find it helpful to defragment certain problem files using iDefrag.

I also continue to find bad blocks on my drives, which can cause hangs and lead to damaged files. Drive Genius’s Scan feature is the best way that I know to detect them.

Lastly, it’s alarming just how many disk problems my customers encounter. SpamSieve now includes various diagnostics to detect and fix incorrect permissions and corrupt files. It also validates parts of its own bundle and advises the user to download a fresh copy if components are missing or damaged. Seeing how often this can happen, it’s a wonder that anything on the Mac works.

A Shift in Google’s Thinking

Kontra:

Above all, despite many examples to the contrary, Google appealed to manifest impartiality: its search results were algorithmically derived, untouched by human biases and thus fair. The list of grandiose promises and statements made by Google that turned out to be false and hypocritical is uncomfortably long.

The Chequered History of MagSafe

Jordan Merrick:

There’s an Apple support article that details how to reduce cable strain and damage on your MagSafe power adapter but that’s about it, it’s not even in the getting started booklet that’s in the box with the Mac (at least it hasn’t been on any Mac I’ve owned). Unless you decided to one day research the best methods for keeping your adapter free of cable damage then you’d never really know. Ironically, this was the exact same problem Apple’s smaller profile 30-pin dock connector cables were experiencing since they shrank it and removed the need to pinch the sides - customers would just yank the cable.

[…]

With the previous T-shaped connector, pull the cable in any direction and it’ll detach. With the L-shaped connector, pull the cable in most directions and it’ll detach. The one direction it won’t detach is if it’s pulled back away from the rear of the Mac (or the rear-right of the Mac), the cable can’t detach since the MagSafe port is recessed. All it needs is a sharp tug of the cable backwards and it’s enough to cause the exact problem MagSafe tried to avoid - a flying Mac.

[…]

By reducing the height and increasing the width of MagSafe, Apple could move back to the more versatile T-shaped connector that all new MacBook Pro/Airs ship with. The magnet is still pretty strong (in fact I think it’s still a little too strong) but the cable’s strain relief appears to be better and my cable has been in constant use for the better part of 8 months and it looks just as good as it did out of the box.

Daylight Savings Time

Dr. Drang:

If, by the way, you think the solution is to stay on DST throughout the year, I can only tell you that we tried that back in the 70s and it didn’t turn out well. Sunrise here in Chicago was after 8:00 am, which put school children out on the street at bus stops before dawn in the dead of winter. It was the same on the East Coast. Nobody liked that.

People complain about the complications DST causes in scheduling, especially in our connected world where international phone calls have to be arranged between people in countries whose time changes occur at different points in the calendar. This is a real problem, but only because our vaunted technology has let us down.

The Power of Abstraction

Graham Lee:

In her keynote speech at QCon London 2013 on The Power of Abstraction, Barbara Liskov referred to several papers contemporary with her work on abstract data types. I’ve collected these references and found links to free copies of the articles where available.

What CS Papers Should Everyone Read?

Ryan Williams (via @CompSciFact):

We all have favorite papers in our own respective areas of theory. Every once in a while, one finds a paper so astounding (e.g., important, compelling, deceptively simple, etc.) that one wants to share it with everyone. So list these papers here!

Embarrassingly, I think I’ve only read one of these, the fun Ken Thompson one about a compiler Trojan horse.

See also: 10 Papers Every Programmer Should Read (At Least Twice) and the 6.033 reading list.

Update (2013-09-10): An old Bruce Schneier post discusses David A. Wheeler’s Countering Trusting Trust through Diverse Double-Compiling.

Friday, March 8, 2013

Google Maps for iPhone 1.1

Google Maps for iPhone 1.1 is an improvement over version 1.0 in that it can now access contacts from your Google account. However, it only does this via search (no browsing), and it still can’t access the iOS contacts database.

Update (2013-03-13): It’s worth reminding that, even better than Google Maps adding iOS Contacts integration, would be for Apple to let iOS users choose the default maps app. Then you could use any existing contacts app with Google Maps.

Wednesday, March 6, 2013

Why Andy Switched to Android

Andy Ihnatko:

The microphone button is crowded right next to the spacebar, and iOS speech-to-text activates with a single careless tap instead of with a deliberate tap-and-hold. When I’m typing fast, I’m accidentally triggering speech-to-text All. The. Freaking. Time.

This affects me in every app except OmniFocus, in which the microphone button is for some reason always disabled. Since I rarely use Siri, I’m considering turning it off to avoid these accidental taps.

And if you don’t like any of the keyboards that ship with Android, you can install one of your own. My add-on keyboard of choice is SwiftKey. It’s doubleplus-brilliant and costs just four damn dollars. […] A three-slot rack of “next word” predictions appears above the keys…and SwiftKey is a very good guesser. […] I find that typing on an Android device is faster and much less annoying than typing on my iPhone. It’s not even close.

I remember liking these sorts of utilities when I was a Palm user. It’s understandable that Apple’s built-in keyboard is simpler, but unfortunately third-party developers aren’t allowed to fill this niche. If I did more mobile typing I could see this as a deal-breaker.

The screen of the iPhone 5 sometimes makes me feel like I’m reading a grocery receipt, not a book. And I never used to read from my phone in bed. Now, if my (still quite beloved) iPad is downstairs and the Galaxy S III is on the nightstand, I’ll spend an hour reading from the Samsung rather than risk cold feet.

This is interesting. I’ve never felt that the iPhone 4S was too small, and in fact I’ve wondered whether I would even like the taller iPhone 5. Yet there have been lots of times when I didn’t have my Kindle with me and would have liked to read from my phone, except that doing so isn’t very comfortable. Is the Galaxy S III just big enough?

Sidenote: It’s sad how much grief Ihnatko is getting in the Macworld comments for what is only his personal tale.

Update (2013-03-14): Part 2:

Almost anything I do that involves one app working with another app is much, much easier on an Android device than on an iPhone, thanks to a deep-rooted mechanism for interapp collaboration.

[…]

In many of my Android reader apps, I can use the volume keys to turn pages, or flip between articles. It’s not the least bit confusing. The volume keys work normally within the app until I look inside the app’s Settings page and click the checkbox to activate the feature. Again: normal behavior until the user deliberately chooses to modify it.

Part 3:

Android is less stable and reliable than iOS, but that doesn’t make it “unstable and unreliable.” I need to force-reboot my iPhone about ten times a year. On Android, it’s… mmmmaybe twenty five? So yes, it’s a higher number on Android, but no, both devices need a kick in the head so infrequently that I can never recall the last time I administered one.

[…]

Most of the time, I could find feature-equal Android versions of the same apps I had been using in iOS. When I couldn’t, I found Android substitutes that I liked just as much or even more.

[…]

The iPhone is still the only phone that has what I consider “a real camera” as opposed to “an excellent smartphone camera.” Both Nokia and HTC have made solid first steps towards bringing their cameras up to that standard. But while they're pointing to their cameras as a signature feature and an object of pride, only Apple is backing up those claims with camera that's truly great from wall to wall and floor to ceiling.

An Embarrassing Bug in Mac App Sandboxing

Jonathan Deutsch:

The technology has caused us and our users grief, cost significant development time, and likely lost our business users. […] The bug appears erroneously as a permissions error when exporting as HTML5. It is caused when there is simply a space (or other escapable character) in the application path.

Tuesday, March 5, 2013

How Emoji Conquered the World

Jeff Blagdon:

In Japanese, personal letters are long, verbose affairs, full of seasonal greetings and honorific expressions that convey the sender’s goodwill to the recipient. The shorter, more casual nature of email lead to a breakdown in communication. “If someone says Wakarimashita you don’t know whether it’s a kind of warm, soft ‘I understand’ or a ‘yeah, I get it’ kind of cool, negative feeling,” says Kurita. “You don’t know what’s in the writer’s head.”

Ugly Font Rendering in PDFs

Dominik Wagner:

The design decision why your personal choice of having ugly fonts in smaller font sizes should be hard baked into generated PDFs puzzles me. It strikes me simply as an over-eager implementation of a feature that makes the world a worse place.

Higher-Order List Operations

Matt Might (via @CompSciFact):

While recursion is better than iteration for functional programming, new functional programmers are unaware of powerful libraries to encapsulate recursion over common data structures like lists.

This post explains some of the common higher-order list operations in Racket and Haskell by re-implementing them.

Bypassing PHP strcmp()

Daniel Regalado reports on how PHP’s strcmp() returns NULL when comparing a string with a non-string, and how if your code uses == (which sees NULL as 0) instead of === it will erroneously think the two are equal (via Colin Barrett).

Saturday, March 2, 2013

The Lightning Digital AV Adapter Surprise

Cabel Sasser notes the limited resolution, lag, and MPEG artifacts when using the adapter:

There’s a lot more going on in this adapter than we expected: indeed, we think the Lightning Digital AV Adapter outputs video by using AirPlay (or similar MPEG streaming).

The adapter apparently has an ARM system on a chip with 256 MB of RAM. It doesn’t work right away when you plug it in because you have to wait for it to boot.

Commenter Apple Neednotknow:

From talking to a friend from Apple last thanksgiving, this was done because of the lack of pins, and the iOS device starts by pushing firmware to the dongle then streams video to the dongle which outputs the hdmi signal. The dongle and firmware combo were described to me as basically an underpowered Apple TV minus the wireless hardware.

Commenter Common Sense:

This is pathetic. We thought the lack of analog audio line out was a major blunder, but this is just unbelievably bad. Reasonable people could understand that Apple needed a new dock connector, but that would be to provide BETTER signals, not worse.

Commenter Frank:

The idea is great: The lightning adapter will be Apples only port and it will remain future proof.

In reality however, the lightning connector also has a limited bandwidth thus they have to compress their data, the conversion to and from the Apple lightning protocol requires lots of processing power, on both sides, and reduces quality. And finally it’s expensive.

On Reddit, thisisnotdave writes:

The Lighting Digital AV adapter does in fact do 1080p for video playback! It DOES NOT do it for screen mirroring, which suck, but its important to make that distinction since neither OP nor the article do so.

roidsrus:

The lightning connector and cable can all support huge amounts of bandwidth, at least USB 3.0 levels, but the NAND controller in the current batch of iDevices can’t. The connector itself is pretty future-proof, though.