Hey there - I'm probably missing something suuuper obvious but is there an idiomatic Moya way for me to load stubs using .json local files?
Or should I just roll something myself and give an escaped string to sampleData.
Cheers! 馃榾
I don't know about being idiomatic, but you could try this approach:
var sampleData: NSData {
let name: String
switch self {
case .Search:
name = "sample_search"
break
}
guard let path = NSBundle.mainBundle().pathForResource(name, ofType: "json"),
data = NSData(contentsOfFile: path) else {
return NSData()
}
return data
}
Provided you have a file named sample_search.json in your bundle.
Aaaand I just realised that was exactly the way to go. Just wanted to make sure there wasn't some nice way I could give a filename to sampleData rather than doing that myself. I think the escaped JSON string in the README example for sampleData made me wonder whether I had to provide some kind of escaped variant of the data also.
Thanks for your help either way - appreciate it 馃槂
@tomj How do you think we could improve our documentation around this? Any suggestions?
@ashfurrow hope #603 is up to scratch 馃槃
Looks great!
Most helpful comment
I don't know about being idiomatic, but you could try this approach:
Provided you have a file named
sample_search.jsonin your bundle.