์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 |
- CollectionView
- Lv2
- Xcode
- rxcocoa
- arkit
- realm
- ํ๋ก๊ทธ๋๋จธ์ค
- TCA
- tableView
- ํจ์คํธ์บ ํผ์ค
- RxSwift
- XCTest
- visionOS
- Kuring
- BOJ
- ios
- reactorkit
- UIKit
- Swfit
- raywenderlich
- BFS
- Flutter
- swift
- MVVM
- SnapKit
- ๋ฐฑ์ค
- combine
- designpattern
- node.js
- SwiftUI
- Today
- Total
lgvv98
[Swift] New access modifier: package ๋ณธ๋ฌธ
[Swift] New access modifier: package
๐ฅ ์บ๋ฟ๋งจ 2024. 4. 5. 02:14New access modifier: package
Introduction
- ํ์ฌ ๋ค๋ฅธ ๋ชจ๋์์ ํน์ ์ฌ๋ณผ์ ์ ๊ทผํ๊ธฐ ์ํด์๋ public์ผ๋ก ์ ์๋์ด์ผ ํจ.
- public ํจํค์ง ๋ด์ธ๋ถ ๋ชจ๋์์ ์ ๊ทผ ๊ฐ๋ฅํ๊ธฐ์ ๋ฐ๋์งํ์ง ์์.
- ๋ฐ๋ผ์ ์๋ก์ด ์ ๊ทผ์ ์ด์๋ฅผ ๋ง๋ค์ด ์ฌ๋ณผ์ ๋ฒ์๋ฅผ ๋ ๋ช ํํ๊ฒ ํ๊ณ ์ ํจ.
- Swift 5.9์์ ๋์
Motivation
- Module Engine in gamePkg:
public struct MainEngine {
public init() { ... }
// `public`์ผ๋ก ์๋๋ ํ๋กํผํฐ
public var stats: String { ... }
// ๋์ผํ ํจํค์ง์ `Game`์์๋ง ์ ๊ทผํ ์ ์๋ `run` ํจ์
public func run() { ... }
}
- Module Game in gamePkg:
import Engine
public func play() {
MainEngine().run() // ๋์ผํ ํจํค์ง ๋ด์ ์์ผ๋ฏ๋ก ์๋ํ ๋๋ก 'run'์ ์ ๊ทผํ ์์์
}
- Client App in appPkg:
import Game
import Engine
let engine = MainEngine()
engine.run() // ์๋ํ ๋์์ด ์๋๋๋ผ๋ ์ฑ์์ `run`์ ์ ๊ทผํ ์ ์์.
Game.play()
print(engine.stats) // ์๋ํ๋๋ก `stats`์ ์ ๊ทผ ๊ฐ๋ฅ
Proposed solution
- ๋์ผ ํจํค์ง์์ ์ฌ์ฉํ๊ธฐ ์ํ ์๋ก์ด ์ ๊ทผ ์ ์ด์ package ๋์
Detailed design
package var package: String {...}
- ์์ ์ฝ๋๋ฅผ ์๋์ฒ๋ผ ๊ฐ์ ๊ฐ๋ฅ
public struct MainEngine {
public init() { ... }
public var stats: String { ... }
package func run() { ... }
}
Use Site
import Engine
public func play() {
MainEngine().run() // ๋์ผ ๋ชจ๋์ด๋ฏ๋ก ์ฌ์ ํ ํด๋น ์ฌ๋ณผ์ ์ ๊ทผํ ์ ์์
}
ํ์ง๋ง ๋ง์ฝ ํจํค์ง ์ธ๋ถ์์ package๋ก ์ ์ธ๋ ์ฌ๋ณผ์ ์ ๊ทผํ๊ณ ์ ํ๋ ๊ฒฝ์ฐ์๋ ์ ๊ทผํ ์ ์์.
Client App
import Game
import Engine
let engine = MainEngine()
engine.run() // Error: cannot find `run` in scope
Package Names
- ์๋ก์ด package ์ ๊ทผ ์ ์ด์๋ฅผ ํด๋น ํ๊ฒ์์ ์ฌ์ฉํ์ง ์์ผ๋ ค๋ฉด false ์์ฑํ๋ฉด ๋๋ฉฐ, ํด๋น ๋ชจ๋์ ํฌํจ๋ package ์ ๊ทผ์ ์ด์๋ ์ฌ์ฉํ ์ ์์. ๊ธฐ๋ณธ์ true
- ์๋ ์ฝ๋์ ๋ํด์ ์ค๋ช ์๋ฉด Game ๋ชจ๋์์ Engine๋ชจ๋์ ํฌํจ๋ package ์ ๊ทผ์ ์ด์ ์ฌ์ฉํ ์ ์์.
.target(name: "Game", dependencies: ["Engine"], packageAccess: false)
Subclassing and Overrides
- ๊ฐ ํ์ฌ ์ก์ธ์ค ๋ ๋ฒจ์ ์ฌ๋ณผ์ ์ฌ์ฉํ๊ฑฐ๋ override ํ ์ ์๋ ์์น๋ฅผ ๋ณด์ฌ์ฃผ๋ ํ
- package๊ฐ ์ถ๊ฐ๋๊ณ ์๋์ฒ๋ผ ์์
- ํ์ฌ ์
๋ ฅํ ๋ณ๋์ ๊ท์น์ด ์ ํด์ง์ง ์์์ผ๋ฉฐ, ํฅํ ๋
ผ์๋ฅผ ํตํด ๊ฒฐ์
- ํ์ฌ ์
๋ ฅํ ๋ณ๋์ ๊ท์น์ด ์ ํด์ง์ง ์์์ผ๋ฉฐ, ํฅํ ๋
ผ์๋ฅผ ํตํด ๊ฒฐ์
(์ฐธ๊ณ ๋งํฌ)
swift-evolution/proposals/0386-package-access-modifier.md at main · apple/swift-evolution
This maintains proposals for changes and user-visible enhancements to the Swift Programming Language. - apple/swift-evolution
github.com
https://github.com/lgvv/wiki/issues/18
New access modifier: package · Issue #18 · lgvv/wiki
New access modifier: package Introduction ํ์ฌ ๋ค๋ฅธ ๋ชจ๋์์ ํน์ ์ฌ๋ณผ์ ์ ๊ทผํ๊ธฐ ์ํด์๋ public์ผ๋ก ์ ์๋์ด์ผ ํจ. public ํจํค์ง ๋ด์ธ๋ถ ๋ชจ๋์์ ์ ๊ทผ ๊ฐ๋ฅํ๊ธฐ์ ๋ฐ๋์งํ์ง ์์. ๋ฐ๋ผ์ ์๋ก์ด ์
github.com
'apple > ๐ Apple Docs & iOS & Swift' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Xcode 16 Beta] Could not download and install iOS 18.0 Simulator runtime with Xcode 16.0 beta (0) | 2024.06.12 |
---|---|
[iOS] infinite carousel DiffableDataSource + CompositionalLayout (0) | 2024.04.16 |
[Natural Language] ํ ์คํธ ๊ฐ ์ ์ฌ์ ์ฐพ๊ธฐ (0) | 2024.03.27 |
[Natural Language] Overview (0) | 2024.03.27 |
[iOS] SwiftData in UIKit (0) | 2023.12.15 |