The function in subject crash to the line:
let imageDataProvider = CGDataProvider(url: urlPath as CFURL)!
This because the final path inside the bundle could be not the same as source input.
I've solved changing this part of code:
public func addTilesetTile(_ tileID: Int, source: String) -> SKTilesetData? {
guard !(self.tileData.contains(where: { $0.hashValue == tileID.hashValue })) else {
log("tile data exists at id: \(tileID)", level: .error)
return nil
}
// bundled images shouldn't have file paths
//let imageName = source.componentsSeparatedByString("/").last!
isImageCollection = true
let inputURL = URL(fileURLWithPath: source)
// read image from file
let imageDataProvider = CGDataProvider(url: inputURL as CFURL)!
with:
public func addTilesetTile(_ tileID: Int, source: String) -> SKTilesetData? {
guard !(self.tileData.contains(where: { $0.hashValue == tileID.hashValue })) else {
log("tile data exists at id: \(tileID)", level: .error)
return nil
}
// bundled images shouldn't have file paths
//let imageName = source.componentsSeparatedByString("/").last!
isImageCollection = true
let inputURL = URL(fileURLWithPath: source)
let filename = inputURL.deletingPathExtension().lastPathComponent
let fileExtension = inputURL.pathExtension
guard let urlPath = Bundle.main.url(forResource: filename, withExtension: fileExtension) else { return nil }
// read image from file
let imageDataProvider = CGDataProvider(url: urlPath as CFURL)!
The function in subject crash to the line:
let imageDataProvider = CGDataProvider(url: urlPath as CFURL)!
This because the final path inside the bundle could be not the same as source input.I've solved changing this part of code:
with: