You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
SR-584 Unexpected behavior when overriding a superclass’ method in an extension
Issue Description:
There is an inconsistent behavior in overriding a property or method of a NSObject subclass.
In Swift you are allowed to override a property or a method in an extension to the class, if the class derives from a NSObject subclass. But in the result the behavior of the class is not the same as if you would override the method or property in the subclass itself.
This is the Base Class:
public class LevelA : NSObject {
public var levelDescription : String {
return "LevelA"
}
}
There is a inconsistent behavior (bug) when overriding a property of a NSObject subclass in swift between these two cases :
Case 1:
public class LevelB1 : LevelA {
}
public extension LevelB1 {
override public var levelDescription : String {
return "LevelB1"
}
}
Case 2:
public class LevelB2 : LevelA {
override public var levelDescription : String {
return "LevelB2"
}
}
You can see the Bug with this code or the attached file in Xcode:
let value1 : LevelA = LevelB1()
let value2 : LevelB1 = LevelB1()
print(value1.levelDescription) // Wrong output in this line!
print(value2.levelDescription)
let value3 : LevelA = LevelB2()
let value4 : LevelB2 = LevelB2()
Attachment: Download
Additional Detail from JIRA
md5: 78a01c56a5144f376019aa284e056e65
duplicates:
Issue Description:
There is an inconsistent behavior in overriding a property or method of a NSObject subclass.
In Swift you are allowed to override a property or a method in an extension to the class, if the class derives from a NSObject subclass. But in the result the behavior of the class is not the same as if you would override the method or property in the subclass itself.
This is the Base Class:
public class LevelA : NSObject {
public var levelDescription : String {
return "LevelA"
}
}
There is a inconsistent behavior (bug) when overriding a property of a NSObject subclass in swift between these two cases :
Case 1:
public class LevelB1 : LevelA {
}
public extension LevelB1 {
override public var levelDescription : String {
return "LevelB1"
}
}
Case 2:
public class LevelB2 : LevelA {
override public var levelDescription : String {
return "LevelB2"
}
}
You can see the Bug with this code or the attached file in Xcode:
let value1 : LevelA = LevelB1()
let value2 : LevelB1 = LevelB1()
print(value1.levelDescription) // Wrong output in this line!
print(value2.levelDescription)
let value3 : LevelA = LevelB2()
let value4 : LevelB2 = LevelB2()
print(value3.levelDescription)
print(value4.levelDescription)
As a result you should not override any properties in a extension. It breaks the ObjC behavior.
The text was updated successfully, but these errors were encountered: