Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update 2019-01-07-import.md #570

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions 2019-01-07-import.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,20 @@ so you should be aware of this possibility
when working with dependencies.
{% endwarning %}

### Typealiasing to Resolve Name Collisions

Often times the easiest way to resolve namespace collisions with multiple modules is to simply typealias the type from the module that you would prefer to use into your local namespace.

```swift
import Foundation
import OurMeasurement // a module that also defines Measurement

// We prefer our new Measurement over the one in Foundation
typealias Measurement = OurMeasurement.Measurement
```

Now whenever Measurement is used in your local namespace, it will use OurMeasurement.Measurement. If you need Foundation's Measurement, it is still available as Foundation.Measurement.

### Clarifying and Minimizing Scope

Beyond resolving name collisions,
Expand Down