Reputation: 14824
In Xcode 8, a Swift project of mine works in Debug mode but fails to link in Release mode:
Undefined symbols for architecture x86_64:
"Swift.UnsafeMutableBufferPointer.(subscript.materializeForSet : (Swift.Int) -> A).(closure #1)"
I can fix the error by changing this line:
let nextPeriod = currentSchedule.periods.filter({ $0.startDate > now }).sorted(by: { $0.startDate < $1.startDate }).first
to:
let nextPeriod = currentSchedule.periods.filter({ $0.startDate > now }).first
but that obviously alters the behavior of my app. Luckily, I can also fix the error by adding the following line to almost any method, initializer, or property observer:
let _ = [""].sorted(by: {$0 < $1})
(I say "almost" any because it doesn't seem to fix the linker error when added to property observers on properties with enum
types I defined myself.)
...What?
Upvotes: 2
Views: 590
Reputation: 19602
This is a compiler bug, which has been fixed in Xcode 8.1
.
Upvotes: 1
Reputation: 1305
At first i thought is that weird code apple inserted in few places with Comparable stuffs... But didn't worked when i added it back. What worked was to step down the optimization level to: fast, single file optimization They messed up this xcode version, storyboards also have huge problems.
Upvotes: 1
Reputation: 1
Had the same problem when migrating to Swift 3.
I got it to work by letting the object that calls the code inherit from NSObject.
Upvotes: 0
Reputation: 21
I had the same problem using sorted(by:
method in one project that I was migrating to Swift 3.
It seems a bug in the compiler and I found this following references:
For now the only workaround that worked for me was change the swift compiler optimization level to None
on Build Settings.
Upvotes: 2