Archive for November 14, 2016

Monday, November 14, 2016

Swift Copy-on-Write PSA: Mutating Dictionary Entries

Ross LeBeau:

Swift’s copy-on-write system usually helps efficiency by delaying the copying of structs until it’s actually needed. However, as shown here, you can run into some pitfalls if you aren’t vigilant of what’s going on under the hood.


The “gotcha” here is that at the time of append, the array is referenced twice – once by the dictionary, and once by the variable items. This triggers copy-on-write, meaning that the entire array is copied to a new location in memory, even though your intention is to mutate a single array.

This is a doubly weird example in Swift because you can’t actually mutate dictionary entries where the value is a struct such as an array. You have to set the array again after appending or wrap the array in a reference type.

Update (2016-11-15): See also: Optimizing a copy-on-write double-ended queue in Swift.

Workflow Update Brings Ability to Interact With Any Web API

Federico Viticci:

Over the past couple of years, I’ve increasingly switched to web services that offer iOS clients and APIs for automation and cross-service integrations.


In the latest version, Workflow can now interact with any API through POST and PUT requests with custom headers, which have been rolled into the ‘Get Contents of URL’ action in addition to existing support for GET requests.


The impressive aspect of Workflow’s deeper web API support isn’t only the sheer amount of possibilities that it opens up for iOS automation, but how it packages everything in a user-friendly interface integrated with the rest of iOS and the app’s features.

I worked with web APIs in Pythonista for iOS before, and it was neither pretty nor accessible. Not only does Workflow allow you to build API requests without typing their syntax manually – it also lets you chain them with variables, data types, and files constructed or fetched with other actions that take advantage of Workflow’s access to iOS frameworks.

Swift’s dump()

Shaps (via iOS Dev Weekly):

ProTip: Why debug with print when you can dump?

dump uses Mirror for introspection.

Microsoft Visual Studio Coming to the Mac

Ben Lovejoy:

Microsoft is hoping to persuade more developers to create Windows apps by bringing its main coding environment – Visual Studio – to the Mac for the first time. Previously, developers had to use a Windows machine or run a virtual machine on a Mac to write Windows software.


The company said that the Mac version uses the same under-the-hood tools of the Roslyn Compiler Platform and MSBuild, and it seemingly leans heavily on app development platform Xamarin Studio. It supports both C# and F# languages.

Rosyna Keller:

Visual Studio for Mac is to Visual Studio as Access is to SQL Server…

Previously: Microsoft Visual Studio Code.

Update (2016-11-17): Here’s Microsoft’s preview page (via Hacker News).

Touché 1.0

Daniel Jalkut:

The simulator is cool, but I immediately noticed a few shortcomings:

  • You have to download Xcode to use it.
  • It’s cumbersome to activate and deactivate.
  • Taking screenshots of the Touch Bar is awkward.

Touché is my answer to those shortcomings. If you’re an everyday user who just wants to play around with the Touch Bar concept, a developer who wants a an easy way to toggle the virtual Touch Bar off and on, or a designer who needs to share screenshots from the Touch Bar frequently, then I think you’re going to love Touché.

Previously: Touch Bar.