SamplePackage icon indicating copy to clipboard operation
SamplePackage copied to clipboard

It suffices to ìmport SamplePackage` into just one of the app's source file, right?

Open rudifa opened this issue 5 years ago • 0 comments

Hello Paul

This issue is just a request for comment.

In my early experiments with Swift Packages in iOS apps, I found that it suffices to import a Swift Package into just one source file in the app, not necessarily the file where the package's items are referenced.

To demo this, I

  • created a simple SamplePackageDemo iOS app
  • added SamplePackage as dependency
  • added import SamplePackage to AppDelegate.swift, not to ViewController.swift
  • referenced it in ViewController
    override func viewDidLoad() {
        super.viewDidLoad()

        print("possibleNumbers= \(Array(1 ... 60).random(7).sorted())")
   }

This build and runs. It also works if I move import SamplePackage to a separate File.swift.

In contrast, Apple frameworks (e.g. UIKit) have to be imported into each file referencing their items.

Is this a Swift Package feature, documented somewhere? Or is it some freaky effect not to be relied upon?

Thank you for any clarification.

rudifa avatar Aug 28 '20 16:08 rudifa