Open swift-ci opened 5 years ago
static
means class
+ final
in a class context, so it's not entirely unreasonable: "subclasses can't override this, but the implementation for all instances might get changed out at run time". I agree that it looks silly, though, since the two words are normally opposites. Any ideas for how to improve the situation?
cc @slavapestov
Comment by Bang Nguyen (JIRA)
@belkadan but in Xcode 9.4 (Swift 4.1), Swizzling a `dynamic static function` doesn't work (I put an example in the Description). Swizzling successfully, but when we call this function, it doesn't go through Objective C runtime.
Additional Detail from JIRA
| | | |------------------|-----------------| |Votes | 0 | |Component/s | Compiler | |Labels | Improvement | |Assignee | None | |Priority | Medium | md5: 836b0a2566d616fb175a8f25b7a2e488Issue Description:
In both Xcode 9.4 (Swift 4.1.2) and Xcode 10 (Swift 4.2), we can declare a function like this:
@objc dynamic static func test() {
}
Xcode 10, this function will be dynamic dispatch. But in Xcode 9, it's static dispatch. It's confusing. In fact, the syntax "dynamic static", "dynamic private static",... should be forbidden, because a function can't be "dynamic" and "static" at the same time.
Eg: this swizzling code works on Xcode 10 (Swift 4.2) but doesn't work on Xcode 9 (Swift 4.1):
class TestSwizzle {
{ return assertionFailure() }
{ print("orignal") }
{ print("swizzled one") swizzled_doSomething() }
}