日記
今日書いたコード
テストの準備を整えた · 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