6

When using Objective-C and importing headers, it made sense to me what was getting imported. For example, I only have to import UIKit but I can use CoreGraphics, for example. How can I tell what other frameworks each framework is importing with Swift? All I'm doing is importing UIKit, but I can still use Core Graphics. I've searched the documentation, but the framework reference doesn't mention it.

Halen
  • 456
  • 4
  • 14

2 Answers2

15

Open your Swift source file. Find the import UIKit line. Command-click on the word UIKit. You'll see what UIKit imports:

import Foundation
import UIKit.NSAttributedString
import UIKit.NSFileProviderExtension
import UIKit.NSLayoutConstraint
import UIKit.NSLayoutManager
import UIKit.NSParagraphStyle
import UIKit.NSShadow
import UIKit.NSStringDrawing
import UIKit.NSText
import UIKit.NSTextAttachment
import UIKit.NSTextContainer
... many more

Command-click on the word Foundation on the first line to see what it imports:

import CoreFoundation
import CoreGraphics
import Foundation.FoundationErrors
import Foundation.NSArray
import Foundation.NSAttributedString
import Foundation.NSAutoreleasePool
import Foundation.NSBundle
import Foundation.NSByteCountFormatter
import Foundation.NSByteOrder
... many more

Repeat until bored or satisfied.

rob mayoff
  • 375,296
  • 67
  • 796
  • 848
  • 1
    Oh my gosh this is amazing. Is there anyway to access this through other means (like the way you could navigate to the objc header files in the file browser)? And I guess my main question is, where can I learn more about Swift modules? I've been searching the documentation and reading the iBook but it's still a mystery. – Halen May 12 '15 at 03:47
  • Swift documentation from Apple is pretty sparse right now. What you can find by command-clicking things in Xcode is pretty much all there is. – rob mayoff May 12 '15 at 15:39
  • Note that just because FrameworkA import FrameworkB (for example `SwiftUI` imports `Combine`), you might not have access to it automatically. I was confused and asked a [question](https://stackoverflow.com/q/67353167/14351818) here, if anyone else is interested. – aheze May 02 '21 at 16:34
0

Refer to the documentation on Swift.

enter image description here

Michael
  • 6,561
  • 5
  • 38
  • 55