问题
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?
回答1:
This is a compiler bug, which has been fixed in Xcode 8.1
.
回答2:
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:
- Swift 2.1 Error sorting in place, only on release builds (same problem in an old Xcode/Swift version)
- https://forums.developer.apple.com/thread/63213 (problem on Xcode 8)
For now the only workaround that worked for me was change the swift compiler optimization level to None
on Build Settings.
回答3:
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.
回答4:
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.
来源:https://stackoverflow.com/questions/39381045/swift-linker-error-in-release-build-fixable-by-adding-code