Reputation: 6359
Now that Swift is open source and that they released some libraries' sources like Foundation
, I was wondering how I could add those into Xcode
so that I can for example have a look into NSString
(even String
?) for any project I would create without adding sources as libraries every time.
A way to have access to the .swift
file and not the public ".h"
version.
Upvotes: 0
Views: 111
Reputation: 126157
The open-source release of Swift includes Foundation and other core libraries... but these are not the same libraries that you get when developing for Apple platforms with Xcode and its included SDKs.
On iOS (and other Apple platforms), Foundation is built in Objective-C. When you develop in Swift using Xcode SDKs, the Swift runtime automatically bridges calls to/from ObjC code. Apple does not publish the source code for this version of Foundation.
When you build with open-source Swift for non-Apple platforms (e.g. Linux), you get the open-source, entirely-Swift version of Foundation instead. This is an completely separate project, which aims to provide Swift equivalents of most of the key primitive and utility class from the original Foundation. (And it's currently incomplete.)
The idea here is that one should be able to write Swift code that makes use of NSURL
, NSDate
, NSFileManager
, NSFormatter
, NSString
(i.e. the set of rich, internationalized string handling features beyond the basics that Swift.String
provides), et cetera, and have it work regardless of whether that code gets built with Xcode for Apple platforms or with open-source Swift for other platforms. So the APIs are the same, but the implementations are different.
However, both implementations of Foundation rely on lower-level libraries that are open source. The most basic parts of Foundation are provided by CoreFoundation — a C library that's been part of Apple's Darwin open source releases for many years. Other parts use the International Components for Unicode library, libdispatch
, and libxml2
.
Anyhow... when you're working in a Swift project in Xcode, the Jump to Definition (Cmd-click) feature should get you to the Swift interfaces for ObjC classes in the SDK, not the ObjC headers for those classes. There isn't a handy way to make Xcode look up the actual source code for those classes (where they happen to be open source), but you can follow the links above.
Upvotes: 3