ぜのぜ

しりとりしようぜのぜのぜのぜ

598日目

日記

今日書いたコード

テストの準備を整えた · Gurrium/ReadGraphemeCluster@6046855 · GitHub

感想

テストの入力をファイルから流し込みたかったのでコードからファイルを読めるようにした。

.xib. xcdatamodeldは勝手にリソースとして扱ってくれるが、.txtはそうではないファイルだった。その場合はPackage.swiftでリソースと明示する必要がある*1

        .testTarget(
            name: "ReadGraphemeClusterTests",
            dependencies: ["ReadGraphemeCluster"],
            resources: [
                .process("input.txt") // koko
            ]
        ),

https://github.com/Gurrium/ReadGraphemeCluster/blob/604685565d949e7995c87d07457bbf627ea686eb/Package.swift#L24-L30

リソースにアクセスするには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