Early last year I had this same issue - here is my workaround (and I must stress that this is a work around, hopefully there is another way to do it now)
- Create a Swift file in your project that you can use to access the data (mine was
Recipe.swift
)
- Drop your CSV into xcode (ignoring target membership - just for convenience (mine was
Recipe.json
))
Create a run script phase to load the data from your CSV to into a Swift class:
set -e
DATA=$(cat "./MyProject/recipe.json" | base64)
echo "import Foundation" > "./MyProject/Recipe.swift"
echo "class Recipe {" >> "./MyProject/Recipe.swift"
echo " static let data = \"$DATA\"" >> "./MyProject/Recipe.swift"
echo "}" >> "./MyProject/Recipe.swift"
This generates a class in your Swift file that looks something like:
import Foundation
class Recipe {
static let data = "..."
}
And then you can decode Recipe.data
when you need to use it.
Of course this isn't a very expandable solution, and I'm sure you can make it better by using lazy initialization, adding the base64 decode directly in the generated class, making paths in the script relative to $SRCROOT
etc. This was just my quick solution that allowed me to continue working on the rest of the project.