图片
let imageName = "image_name"
let imageType = "png"
let directory = "Data/images"
func getImage() -> UIImage {
let path = Bundle.main.path(forResource: imageName, ofType: imageType, inDirectory: directory)!
return UIImage(contentsOfFile: path)!
}
JSON
let jsonName = "json_name"
let extensionName = "json"
let directory = "Data/json"
func getJsonString() -> String? {
let url = Bundle.main.url(forResource: jsonName, withExtension: extensionName, subdirectory: directory)
do {
let jsonString = try String(data: Data(contentsOf: url!), encoding: .utf8)!
return jsonString
} catch {
return nil
}
}
网友评论