dannliu
(Danny Liu)
1
Hi all, I am reading the source code of NotifcationCenter, however, there is only the implementation of open func addObserver(forName name: NSNotification.Name?, object obj: Any?, queue: OperationQueue?, using block: @escaping (Notification) -> Void). I searched the whole swift-corelibs-foundation project and failed to get func addObserver(_ observer: Any, selector aSelector: Selector, name aName: NSNotification.Name?, object anObject: Any?) implementation.
I guess I missed some basic points about the foundation project 
AlexanderM
(Alexander Momchilov)
2
There's no Objective C runtime on Linux, and by extension, no target-selector based callbacks.
Why do you need it? The closure variant is strictly more expressive.
dannliu
(Danny Liu)
3
Hi AlexanderM,
Thanks for your explanation.
Why I posted this question is that I compared the source code with the Xcode documentation and find not all APIs listed could be found in the source code. So I wonder where can I find the implementations of these APIs or these ones are not open source?
I am not familiar with Swift On Linux. So does foundation lib only contains source code works for all platforms
hartbit
(David Hart)
4
There are two Foundation projects which share very similar APIs:
- The one Apple provides for their platforms: it's the historical one, is closed source, and is written in Objective-C.
- The one available for all other platforms: it's open source, written in Swift, and is the one you've been looking at.
The API you're looking for is only available on Apple's closed source Foundation project because it requires the Objective-C runtime, which is not available on non-Darwin platforms. There are other API differences between the two projects.
2 Likes
dannliu
(Danny Liu)
5
Very clear! That's background I need to know.