I have a very small Swift 2.0 project which should run on 7.1 and newer.
It should use WKWebView on iOS > 8.0 and UIWebView on iOS < 8.0.
As soon as I add the WKWebView I can't compile the app again:
import UIKit
import WebKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
if #available(iOS 8.0, *) {
let w = WKWebView()
w.frame = self.view.frame
w.autoresizingMask = [UIViewAutoresizing.FlexibleWidth, UIViewAutoresizing.FlexibleHeight]
self.view.addSubview(w)
} else {
let w = UIWebView()
w.frame = self.view.frame
w.autoresizingMask = [UIViewAutoresizing.FlexibleWidth, UIViewAutoresizing.FlexibleHeight]
self.view.addSubview(w)
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
When I compile for the simulator I have no problems at all, but when compiling for devices I get the following warning:
ld: warning: URGENT: all bitcode will be dropped because '/Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.0.sdk/System/Library/PrivateFrameworks/WebKit.framework/WebKit.tbd' was built without bitcode. You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE), obtain an updated library from the vendor, or disable bitcode for this target. Note: This will be an error in the future.
And more importantly this error:
CopySwiftLibs /Users/<user>/Library/Developer/Xcode/DerivedData/<project>/Build/Products/Debug-iphoneos/<project>.app
cd "/Users/<user>/Xcode Apps/<project>"
export CODESIGN_ALLOCATE=/Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/codesign_allocate
export PATH="/Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Applications/Xcode-beta.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-stdlib-tool --copy --verbose --sign D0AFAF3A974180D3158F01A86EF966D63BD20E97 --scan-executable /Users/<user>/Library/Developer/Xcode/DerivedData/<project>/Build/Products/Debug-iphoneos/<project>.app/<project> --scan-folder /Users/<user>/Library/Developer/Xcode/DerivedData/<project>/Build/Products/Debug-iphoneos/<project>.app/Frameworks --scan-folder /Users/<user>/Library/Developer/Xcode/DerivedData/<project>/Build/Products/Debug-iphoneos/<project>.app/PlugIns --platform iphoneos --destination /Users/<user>/Library/Developer/Xcode/DerivedData/<project>/Build/Products/Debug-iphoneos/<project>.app/Frameworks --strip-bitcode
2015-06-09 13:01:56.469 swift-stdlib-tool[18236:280135] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSCFConstantString substringFromIndex:]: Index 7 out of bounds; string length 0'
*** First throw call stack:
(
0 CoreFoundation 0x00007fff9814403c __exceptionPreprocess + 172
1 libobjc.A.dylib 0x00007fff95f8976e objc_exception_throw + 43
2 CoreFoundation 0x00007fff98143eed +[NSException raise:format:] + 205
3 Foundation 0x00007fff94579d4e -[NSString substringFromIndex:] + 118
4 swift-stdlib-tool 0x000000010e60af91 _Z11parse_machoI9Pointer64I12LittleEndianEEiijjU13block_pointerFvP8NSStringEU13block_pointerFvP6NSUUIDE + 689
5 swift-stdlib-tool 0x000000010e608821 _Z11parse_machoijjU13block_pointerFvP8NSStringEU13block_pointerFvP6NSUUIDE + 321
6 swift-stdlib-tool 0x000000010e608adb _Z7processP8NSStringU13block_pointerFvS0_EU13block_pointerFvP6NSUUIDE + 331
7 swift-stdlib-tool 0x000000010e60a424 main + 3316
8 libdyld.dylib 0x00007fff90fe65c9 start + 1
9 ??? 0x0000000000000010 0x0 + 16
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Command /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-stdlib-tool failed with exit code 6
To avoid linking errors I added WebKit as Framework and marked it as optional.
Is there any way to support 7.1 with a WKWebView UIWebView switch without that weird compiler bug?