Archive for November 8, 2016

Tuesday, November 8, 2016

Passing an Array of Strings From Swift to C

Ole Begemann:

The type checker allows you to pass a String value to an UnsafePointer<Int8> or UnsafePointer<UInt8> parameter. When you do that, the compiler will transparently create a buffer containing the UTF-8-encoded, null-terminated string, and pass a pointer to that buffer to the function.


However, some C functions take an array of strings (a char ** or char *[]), and there is no built-in support in Swift for passing a [String] to a char ** parameter.


The full type of the strlen function as imported by Swift looks like this[…]

How to Badge an App’s Icon in the Dock

Matthias Gansrigler:

Add this key-value pair to your Info.plist: NSUserNotificationAlertStyle with a string value of either banner (recommended by Apple) or alert. Supposedly, there’s another value, none, but that hasn’t worked for me yet – the app won’t appear in the Notifications preference pane.

Having the key-value pair in your Info.plist has no downside if you don’t use NSUserNotifications. There’s only the upside of having the user be able to disable your app’s badges if they like.

Jeff Johnson:

The documentation for NSUserNotification is sparse and implies that Notification Center handles everything automatically. The reality is that developers need to do almost everything themselves.


There is no API to determine whether the user has “Badge app icon” checked in System Preferences. I was stuck on that, but the trick here, which Rig discovered, is that when “Badge app icon” is unchecked, your app’s calls to setBadgeLabel: will not actually set the badge label. This is analogous to deliverNotification: in that you should call the method regardless, and Notification Center determines whether anything happens as a result, according to the user’s preferences.

However, you may still want your own preference for privacy.

You’ll also need to call [[NSApp dockTile] setBadgeLabel:nil] in applicationWillTerminate: otherwise the Dock badge will remain visible after the app quits. And you may want to call it in applicationDidFinishLaunching: too, in case your app crashed before it could clear the previous badge.

Windows File System Compression Had to Be Dumbed Down

Raymond Chen:

I noted some time ago that when you ask Windows to use file system compression, you get worse compression than WinZip or some other dedicated file compression program, for various reasons, one of which is that file system compression is under soft real-time constraints.


The requirement that a file compressed on one system be readable by any other system allows a hard drive to be moved from one computer to another. Without that requirement, a hard drive might be usable only on the system that created it, which would create a major obstacle for data centers (not to mention data recovery).

And one of the limiting factors on how fancy the compression algorithm could be was the Alpha AXP.

A Wish List for the Mac App Store

Dan Counsell:

Many developers have to make the difficult choice between degrading the functionality of their software or leaving the MAS to sell online. […] Things are so acute that entire categories of apps cannot be distributed in the store because they cannot be sandboxed without crippling their feature set (e.g. developer tools, system utilities, and pro apps).


In-app purchases are killing the user experience, but they are currently the only way Apple allows developers to achieve incremental revenue. As a result, one of the only options available is ‘liteware’ with piecemeal in-app purchases, annoying ads, and free apps that “trick” you into buying more later. Devs are stuck between a rock and a hard place: They can’t achieve incremental revenue without in-app purchases, but are punished by consumers for the terrible experience.


Apple has made a lot of progress in reducing the average time it takes for an app to be reviewed, pushing the average app store review time down to just one day from a previous average of eight. That said, Apple’s app review process is incredibly inconsistent.

When sandboxing was introduced, I thought that more entitlements would be forthcoming each year. The theory was that Apple would prefer more apps to be sandboxed, with their functionality controlled by entitlements, than to have them remain wholly unsandboxed. But that hasn’t really happened. If anything, we’ve seen more tightening.

My last four app reviews were 4 hours, 3 days, 6 hours, and 2 days. Oddly, sometimes it takes 1–2 days after “Ready for Sale” before the update actually shows up in the Mac App Store.

Update (2016-11-15): Nick Heer:

As far as I can see, the only apps that take well to the Mac App Store — aside from Apple’s apps — are single-purpose lightweight consumer utility apps. For instance, a while ago, I was trying to find an audio A/B testing app. After fruitlessly scouring the web for probably half an hour, I tried the App Store and found a couple of decent contenders.

The Importance and Potential of Twitter

Ben Thompson (Hacker News):

And yet it is Twitter that has reaffirmed itself as the most powerful antidote to Facebook’s algorithm: misinformation certainly spreads via a tweet, but truth follows unusually quickly; thanks to the power of retweets and quoted tweets, both are far more inescapable than they are on Facebook.


To be clear, Twitter has a real abuse problem that it has been derelict in addressing, a decision that is costly in both human and business terms; there is real harm that comes from the ability to address anyone anonymously, including the suppression of viewpoints by de facto vigilantism. But I increasingly despair about the opposite extreme: the construction of cocoons where speech that intrudes on one’s world view with facts is suppressed for fear of what it does to the bottom line, resulting in an inert people incapable of finding common ground with anyone else.

This is why Twitter must be saved: the combination of network and format is irreplaceable, especially now that everyone knows it might not be a great business.

Austin Gardner-Smith (via Hacker News):

I’ve always been a big fan of Twitter as a platform. But like most people I’ve met who share that sentiment, I’m a bit disappointed by the grown-up it’s become.


These things happen. I’m not here to point out all the mistakes the management team has or has not made - these are not easy decisions to make and no one likes a Monday morning quarterback. But around 2010, when I was working on Pinyadda, I believed that Twitter was going to become something very different from what it looks like today. I thought it had a chance to become a protocol, of sorts.

Twitter created and controlled perhaps the most important new protocol since HTTP. What if it had embraced third-party developers and found a different business model than advertising?