日記
今日書いたコード
テストの準備を整えた · Gurrium/ReadGraphemeCluster@6046855 · GitHub
感想
テストの入力をファイルから流し込みたかったのでコードからファイルを読めるようにした。
.xibや. xcdatamodeldは勝手にリソースとして扱ってくれるが、.txtはそうではないファイルだった。その場合はPackage.swiftでリソースと明示する必要がある*1。
.testTarget(
name: "ReadGraphemeClusterTests",
dependencies: ["ReadGraphemeCluster"],
resources: [
.process("input.txt") // koko
]
),
リソースにアクセスするにはBundle.moduleを使う*2。
これは:hee:ポイント
If you want to make a package resource available to apps that depend on your Swift package, declare a public constant for it. https://developer.apple.com/documentation/xcode/bundling-resources-with-a-swift-package#Access-a-resource-in-code