일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- TCA
- 패스트캠퍼스
- combine
- reactorkit
- designpattern
- RxSwift
- SnapKit
- UIKit
- BOJ
- ios
- Xcode
- Lv2
- XCTest
- 백준
- rxcocoa
- Swfit
- node.js
- WWDC24
- swift
- Kuring
- raywenderlich
- Flutter
- CollectionView
- tableView
- MVVM
- realm
- arkit
- 프로그래머스
- SwiftUI
- visionOS
Archives
- Today
- Total
lgvv98
swift @_spi (System Programming Interfaces) 본문
swift @_spi (System Programming Interfaces)
api와 spi 정의
- api란?
- swift에서 사용할 수 있는 Application Programming Interface의 약자.
- spi란?
- api 중 일부는 특정 클라이언트에게만 제공.
spi는 실험적.
- apple에서 밑줄 있는 속성은 사용하지 말라고 권장. 밑줄 있는 속성의 의미는 변경될 수 있고 안정화 전에 Swift의 진화 과정을 거칠 확률이 높음.
- spi의 경우 기존 접근제어자보다 우선순위가 높음.
spi 선언
public class PaymentFeature {
public func pay() async {}
@_spi(bitcoin) public func payWithBitCoin() async {}
@_spi(apple) public func payWithApple() async {}
@_spi_available(watchOS 9, *)
@available(tvOS, unavailable)
public private(set) var items = [String]()
public init() {}
}
spi 사용
import SwiftUI
import PaymentFeature
class ViewModel {
private let feature = PaymentFeature()
func pay() async {
await feature.pay()
}
}
@_spi 가 붙은 함수에 접근하기 위해서는 import 부분을 수정해야 함.
다중으로 사용할 수도 있음.
프로젝트 적용 예시
아래의 형태로 사용하거나, 테스트 코드를 작성할 때 프로퍼티르 private으로 되어 있어서 난감한 경우 이를 @_spi로 해결할 수 있어 보임.
public struct MyFeature {
var add: () -> ()
var revmoe: () -> ()
@MainActor
public static let liveValue: Self = .init {
return ()
} revmoe: {
return ()
}
@MainActor
@_spi(test) public static let testableValue: Self = .init {
return ()
} revmoe: {
return ()
}
}
(참고)
https://blog.eidinger.info/system-programming-interfaces-spi-in-swift-explained
https://ios-development.tistory.com/1452
'apple > Docs, iOS, Swift' 카테고리의 다른 글
SwiftUI .swipeActions not working (0) | 2024.08.28 |
---|---|
iOS Translation Framework (0) | 2024.08.28 |
CloudKit 정리 코드 예제 #3 (0) | 2024.08.18 |
iOS TipKit 사용 예제 정리 (0) | 2024.08.18 |
Swift withTaskCancellationHandler (0) | 2024.08.17 |
Comments