Archive for August 30, 2016

Tuesday, August 30, 2016

Sort Descriptors in Swift

Chris Eidhof (tweet):

A sort descriptor uses two runtime features of Objective-C: the key is a key path, and key-value coding is used to lookup the value of that key at runtime. […]

This is a pretty cool use of runtime programming, especially when you realize the array of sort descriptors can be built at runtime, say based on a user clicking a column heading.


Rather than copying and pasting, we can define a function with an interface that is much like NSSortDescriptor, but without the runtime programming. This function takes a key and a comparison method, and returns a sort descriptor (the function, not the class NSSortDescriptor). Here, key is not a string, but a function. To compare two keys, we use a function isOrderedBefore. Finally, the result type is a function as well, even though that is slightly obscured by the typealias.

However, he does not show how to achieve functionality equivalent to NSSortDescriptor, e.g. pulling the identifier out of a table column and sorting by that. Of course, this is trivial by leaning on the Objective-C runtime, but can it be done efficiently and concisely with a pure Swift object?

One drawback of the function-based approach is that functions are opaque. We can take an NSSortDescriptor, print it to the console, and we get some information about the sort descriptor: the key path, the selector name and whether it’s ascending.

This also prevents straightforwardly persisting the sort descriptor or translating it into a database query.

Apple, Ireland, and the EU


At this stage, the Commission has reasons to consider that the tax ruling granted to Apple constitute State aid pursuant to Article 107(1) of the Treaty. Accordingly, the Commission has doubts that Apple is paying a sufficient amount of taxes in Ireland. The rulings are imputable to Ireland and would constitute a use of State resources in terms of foregone tax revenues. In line with the case-law of the Court of Justice of the European Union (Joined Cases C-182/03 and C-217/03 Forum 187), tax rulings can provide an advantage to the undertaking to which they are granted if those rulings approve of a pricing arrangement which departs from conditions which would have been set between independent market operators (the arm’s length principle).

The Commission examined whether the pricing arrangements in the tax rulings concluded between the Irish tax authorities and Apple depart from conditions which would have been set between independent market operators. In the present case, the methods used to determine the profit allocation to the two branches ASI and AOE are not supported by an economic assessment and seem at least in part to be guided by employment considerations which raises doubts as to whether a prudent independent market operator would have accepted a similar pricing arrangement in the same situation. Instead, the authorities accepted to calculate the profit attributable to the branches on the basis of actual costs without this choice being reasoned. As costs should normally be an appropriate net profit indicator for routine functions not requiring a specific valuable such as a unique intellectual property right, which at least existed in relation to AOE, the Commission doubts the appropriateness of the transfer pricing method chosen.

European Commission (via Tim Hardwick):

The European Commission has concluded that Ireland granted undue tax benefits of up to €13 billion to Apple. This is illegal under EU state aid rules, because it allowed Apple to pay substantially less tax than other businesses. Ireland must now recover the illegal aid.


Following an in-depth state aid investigation launched in June 2014, the European Commission has concluded that two tax rulings issued by Ireland to Apple have substantially and artificially lowered the tax paid by Apple in Ireland since 1991. The rulings endorsed a way to establish the taxable profits for two Irish incorporated companies of the Apple group (Apple Sales International and Apple Operations Europe), which did not correspond to economic reality: almost all sales profits recorded by the two companies were internally attributed to a “head office”. The Commission’s assessment showed that these “head offices” existed only on paper and could not have generated such profits. These profits allocated to the “head offices” were not subject to tax in any country under specific provisions of the Irish tax law, which are no longer in force. As a result of the allocation method endorsed in the tax rulings, Apple only paid an effective corporate tax rate that declined from 1% in 2003 to 0.005% in 2014 on the profits of Apple Sales International.

Tim Cook (via Mitchel Broussard, Hacker News, Slashdot, Investor FAQ):

The opinion issued on August 30th alleges that Ireland gave Apple a special deal on our taxes. This claim has no basis in fact or in law. We never asked for, nor did we receive, any special deals. We now find ourselves in the unusual position of being ordered to retroactively pay additional taxes to a government that says we don’t owe them any more than we’ve already paid.

As I understand it, Apple didn’t get a special deal; rather, they went to great lengths to take advantage of a tax loophole. Ireland was happy with this—it got lots of jobs and taxes on revenue that didn’t really have to do with Ireland. The EU says that the Apple/Ireland position is in violation of what Ireland agreed to when joining the Common Market. The business structure is definitely illegal now, which is why Apple changed it in 2015, but it was allegedly also illegal in 1991, which is why they want Apple to pay retroactively. Cook’s letter seems to be aimed at getting Ireland to fight the EU on its behalf.

Kirk McElhearn:

Apple is saying that sales in EU countries are actually made by Apple’s Irish subsidiary; that any brick and mortar or online store in another country is actually part of Apple Ireland. That the store where I buy my iPhone in the UK isn’t really in the UK, as far as taxes are concerned.

Nick Heer:

Before Ireland adjusted their tax code in 2015 to remove the so-called “Double Irish” scheme, Google, Facebook, and many other large companies made use of the country’s policies to dramatically reduce the tax they paid outside of the United States. Earlier this year, Google was accused of using a similar scheme to Apple’s in the U.K., which they ended up settling for far less than the expected amount.

Todd Ditchendorf:

Regardless of what you think of Apple’s tax evasion strategy, it doesn’t jibe with Cook’s usual conspicuous self-righteousness.

Update (2016-08-31): Dan Bookoff:

“The Irish Revenue don’t do deals,” Noonan told CNBC on August 30. “They issue opinions to clarify a tax situation for individual companies, but we never do deals.”


One reason all this might seem odd to Americans is that the “special treatment” Ireland is accused of giving Apple is similar to incentives American states give companies all the time legally.

Massachusetts, for instance, put together $145 million in incentives to persuade General Electric to move from suburban Connecticut to Boston.

Update (2016-09-06): Mark Sullivan (via Hacker News):

To get the other side of the argument I went to Matt Gardner, the director of the Institute on Taxation and Economic Policy (the research umbrella for Citizens for Tax Justice). The CTJ is nonpartisan and nonprofit, and it’s funded by some of the same foundations that fund NPR. As it turns out, Gardner energetically disagrees with many of the statements in Cook’s letter. Here are his responses to Cook’s main points.


It’s clear as day—and this was one of the findings of the 2013 Senate subcommittee—that there was no sensible business reason to set up those subsidiaries except to avoid paying taxes. It makes no difference that Ireland cheerfully agreed to it. It’s still a tax dodge, just a state-sanctioned tax dodge.


All the EU is saying is that Ireland’s tax rate is 12.5% and wouldn’t it be nice if Apple actually paid that tax rate. It’s certainly not coming up with a new tax regime that’s never been seen before.


It sounds like what they’re saying is that these ought to be thought of as U.S. profits, which makes it hard to understand why they have been so eager to report these profits in Ireland up until now.

Todd Ditchendorf reminds us of “just do what’s right” and “the bloody ROI.”

Update (2018-06-21): Tim Cook:

Honestly speaking, we didn’t come to Ireland for tax.

Update (2018-09-19): Mitchel Broussard:

Just over two years after the European Commission ruled that Apple was receiving illegal state aid from Ireland -- where it had reportedly paid less than 2 percent in taxes compared to the country’s headline 12.5 percent corporate tax rate -- Apple has now paid back the entire 13.1 billion euros ($15.3 billion) it owed in back taxes (via Reuters).

Update (2020-08-27): Valentina Pop and Sam Schechner (via John Gruber):

Apple Inc. won a major battle with the European Union when the bloc’s second-highest court on Wednesday sided with the U.S. company over a €13 billion ($14.8 billion) tax bill that EU antitrust officials had said the company owed to Ireland.