Using Xcode 12.5 I have identified an issue with this instruction "(Self.self)" when it runs on a build created setting SWIFT_OPTIMIZATION_LEVEL to -O (Optimize for speed).
The instruction above is executed in a superclass (subclass of UIView) when it to load a NIB:
Instead of getting the right subclass name, it simply returns "Self" and this generate the following error:
*** Terminatingappduetouncaughtexception'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: '...' with name 'Self''
This never happens before with previous versions of Xcode, and it still does not happen when the build is generate without using optimization -Onone.
To fix it I have changed "(Self.self)" with "(type(of: self))". This way it works, but I think that it should be investigate why the original version causes that kind of issue when Swift is optimized.
Forcing optimization in Debug, I was able to reproduce the issue. I have also tried to insert a breakpoint before the crash, trying to execute the instruction in Console with po command, but it works as expected, printing the right class name.
The text was updated successfully, but these errors were encountered:
classViewController: UIViewController {
overridefuncviewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.letc = MyClass()
print(c.classname)
}
}
When I activate -O optimization in Debug, the Console prints: Self.
Just to confirm that this issue is not directly related to the app I am working on, but it is reproducible in any context.
Additional Detail from JIRA
md5: 4cc049e4929f10d973d6a2409610d84f
Issue Description:
Using Xcode 12.5 I have identified an issue with this instruction
"(Self.self)"
when it runs on a build created settingSWIFT_OPTIMIZATION_LEVEL
to-O
(Optimize for speed).The instruction above is executed in a superclass (subclass of
UIView
) when it to load a NIB:Instead of getting the right subclass name, it simply returns
"Self"
and this generate the following error:This never happens before with previous versions of Xcode, and it still does not happen when the build is generate without using optimization
-Onone
.To fix it I have changed
"(Self.self)"
with"(type(of: self))"
. This way it works, but I think that it should be investigate why the original version causes that kind of issue when Swift is optimized.Forcing optimization in Debug, I was able to reproduce the issue. I have also tried to insert a breakpoint before the crash, trying to execute the instruction in Console with
po
command, but it works as expected, printing the right class name.The text was updated successfully, but these errors were encountered: