What is difference between Objective-C NSCache.m
and Foundation NSCache
?
When I use NSCache
in Swift, does it use Foundation's NSCache
or Objective-C's?
If you "jump to definition" about NSCache
in Swift then Xcode shows the following file. It imports <Foundation/NSObject.h>
, so I think it's using Foundation's NSCache
, but the code is also ObjC, so I'm confused.
iOS and other Apple platforms use the closed-source Apple version of Foundation, which is neither of the links you've provided.
The first link is swift-corelibs-foundation, which is a reimplementation of much of Foundation for non-Apple platforms (particularly Linux) in Swift. It is not currently used on any Apple platform, but is primarily managed by Apple along with community contributors.
Your second link is from GNUStep which is an open-source reimplementation of Cocoa that Apple is not involved with. The full project is an implementation of the OpenStep API, which was developed by NeXT. It's an interesting project, but has no real intersection with the Apple ecosystem. It pre-dates the Apple acquisition, and is much closer to NeXTSTEP than to iOS.
Your screenshot is the correct version: the proprietary, Objective-C version of Foundation. The source code for that is not available, only the headers. If your goal is to see the actual implementation of NSCache on iOS, that's not available. The best you can do is reverse-engineer it with something like Hopper. (Even with that, it's usually easiest to reverse engineer the macOS version, and assume the iOS version is the same.)
The version in swift-corelibs-foundation is intended to have very similar behavior to the Apple version, so is a fairly good way to determine what the behavior is supposed to be, but the implementation is generally completely different and may not behave the same in all corner cases.