IDE: Fire Version: Version 10.0.0.2398 (develop) built on talax, 20190425-095831. Commit ffbeaf4. Target (If relevant): iOS Description:
I am trying to extend the UIViewController with a helper to easier instantiate styoboard-based view controller with the commonly used approach like (from www.raywenderlich.com):
If I try to compile this I am getting the following error: E: Unknown type "NSObjectProtocol" [/Users/x/Development/Projects/x/x/version-3/config-app/x/Extensions/UIViewController+Storyboard.swift (3)]
Expected Behavior:
The above extension should compile as expected.
Actual Behavior:
An Unknown type error is thrown by the compiler while compiling an iOS application
I am not sure if this issue is related to:
Steps:
Create a new iOS application project
Added the above code snippet in a file e.g. UIViewController+Storyboard.swift
I have tried this by adding the line I noticed in SwiftBaseLibrary:
#if DARWIN
public typealias NSObjectProtocol = INSObject
public typealias INSObjectProtocol = INSObject
#endif
after adding that the NSObjectProtocol error disappears but then I am getting the error: E: Cannot assign wrapped nullable to not nullable type (String) [/Users/x/Documents/NSObjectProtocol/UIViewController+Storyboard.swift (16)]
which is line: return NSStringFromClass(Self.self) as? String and to resolve this compiler error I have updated this line to: return NSStringFromClass(Self.self) as! String
if I compile the project now I am getting the following internal compiler error in the Linking for Simulator-step:
-> Task Link started for NSObjectProtocol, Toffee-iOS.
-> Phase Linking for Simulator started.
> ld: Undefined symbols for architecture x86_64:
> ld: "_OBJC_CLASS_$___UIViewController", referenced from:
> ld: objc-class-ref in NSObjectProtocol.a(__$Extension$TypeConstrained-aaa6913d9e6e832d5d1f0784aed517a2.o)
> ld: "_OBJC_CLASS_$_instancetype", referenced from:
> ld: objc-class-ref in NSObjectProtocol.a(__$Extension$TypeConstrained-aaa6913d9e6e832d5d1f0784aed517a2.o)
E: ld: symbol(s) not found for architecture x86_64
<- Phase Linking for Simulator failed.
the problem is that static var defaultFileName: String { returns. NON-nullable String, but as? String is nullable. you’ll want as!, yes. so that’s the correct fix. The same would apply to Xcode?
Curious, that does sound like a compiler bug. I’ll log.
Well, actually in Xcode 10.1 you get a similar warning and when you change it to as! you are getting the following error: Forced cast of 'String' to same type has no effect and suggests to change the line to return NSStringFromClass(Self.self) (which give no errors in both Xcode and Fire) so that’s all good!