Open
Description
Previous ID | SR-14815 |
Radar | rdar://problem/79653034 |
Original Reporter | @mickeyl |
Type | Bug |
Environment
Swift 5.4, Ubuntu 20.x
Additional Detail from JIRA
Votes | 0 |
Component/s | Foundation |
Labels | Bug |
Assignee | None |
Priority | Medium |
md5: cb6a9bc2b9d5e55753c5d7918a8daec1
Issue Description:
Please see the following example program:
import Foundation
class Adapter {
enum State {
case created
case searching
case notfound
case present
case gone
}
public static let DidUpdateState = Notification.Name("Adapter.DidUpdateState")
public private(set) var state: State = .created {
didSet {
NotificationCenter.default.post(name: Self.DidUpdateState, object: self)
}
}
func doSomething() {
self.updateState(.searching)
}
}
extension Adapter {
func updateState(_ next: State) {
guard self.state != next else {
return
}
self.state = next
}
}
class ConcreteAdapter: Adapter {
override init() {
super.init()
NotificationCenter.default.addObserver(forName: Self.DidUpdateState, object: self, queue: nil) { n in
print("Success: Notification did arrive!")
}
print("subscription done")
}
}
let adapter = ConcreteAdapter()
adapter.doSomething()
print("exiting program...")
On Apple-platforms, this prints `Success: Notification did arrive!` – on Linux, it doesn't.