Geon

Write Swift macros(2) 본문

SwiftUI/지식 창고

Write Swift macros(2)

jgkim1008 2024. 11. 13. 23:51

Macro tests

- test를 통해 매크로의 에러 여부를 파악할수 있다.

let testMacros: [String: Macro.Type] = [
    "SlopeSubset" : SlopeSubsetMacro.self,
]

final class WWDCTests: XCTestCase {
    func testSlopeSubset() {
        assertMacroExpansion(
            """
            @SlopeSubset
            enum EasySlope {
                case beginnersParadise
                case practiceRun
            }
            """, 
            expandedSource: """

            enum EasySlope {
                case beginnersParadise
                case practiceRun
                init?(_ slope: Slope) {
                    switch slope {
                    case .beginnersParadise:
                        self = .beginnersParadise
                    case .practiceRun:
                        self = .practiceRun
                    default:
                        return nil
                    }
                }
            }
            """, 
            macros: testMacros
        )
    }
}

 

- 해당 wwdc 영상은 추후 한번더 확인해봐야겠다.

 

 

출저: https://developer.apple.com/videos/play/wwdc2023/10166

'SwiftUI > 지식 창고' 카테고리의 다른 글

Write Swift macros(1)  (0) 2024.11.12
Discover Observation in SwiftUI  (0) 2024.11.11
Demystify SwiftUI performance  (0) 2024.11.10
Explore UI animation hitches and the render loop  (0) 2024.11.09
Image DownSampling  (1) 2024.11.08