0

I am currently writing a workout plan app that saves a user (a struct that contains all the data like personal data, workouts,...) as encoded as json into the file manager using this path and the following two methods:

let userSavePath = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0].appendingPathComponent("savedUser.json")

func encodeObj2JSON<T: Codable>(obj: T) -> Data? {
    let encoder = JSONEncoder()
    let encodedObj = try? encoder.encode(obj)
    return encodedObj
}

func saveObj<T: Codable>(obj: T, path: URL) {
    let encodedObj = encodeObj2JSON(obj: obj)
    try? encodedObj!.write(to: path)
}

saveObj(obj: user, path: userSavePath)

I now want that file to be accessible using Finder/iTunes. Under Finder/iPhone/Files (I do not know how this looks in iTunes) some apps can exchange files between the iOS device and the Mac/PC. I want my "savedUser.json" to be accessible here, so that I can copy that file to my pc or transfer a different json to my device. I have no idea where to start, sadly I could not find any helpful information during my research. Any kind of help would be appreciated.

Edit: Solution for my problem

It seems like I was just to stupid to google. The solutions is simply adding UIFileSharingEnabled to the info.plist and set it to yes (How to enable file sharing for my app?)

0 Answers0