Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func saveImage() {
- let documentsDirectoryURL = try! FileManager().url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
- let file2ShareURL = documentsDirectoryURL.appendingPathComponent("config.n2kHunt")
- var json: Any?
- let encodedData = try? JSONEncoder().encode(products)
- if let data = encodedData {
- json = try? JSONSerialization.jsonObject(with: data, options: .allowFragments)
- if let json = json {
- do {
- try String(describing: json).write(to: file2ShareURL, atomically: true, encoding: .utf8)
- } catch {
- print("unable to write")
- }
- }
- }
- }
- (
- {
- identity = "blah-1";
- major = 245;
- minor = 654;
- url = "https://web1";
- uuid = f54321;
- },
- {
- identity = "blah-2";
- major = 543;
- minor = 654;
- url = "https://web2";
- uuid = f6789;
- }
- func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
- do {
- let string2D = try? String(contentsOf: url)
- let jsonData = try? JSONSerialization.data(withJSONObject: string2D)
- do {
- products = try JSONDecoder().decode([BeaconDB].self, from: jsonData!)
- } catch let jsonErr {
- print("unable to read (jsonErr)")
- }
- } catch {
- print("application error")
- }
- }
Add Comment
Please, Sign In to add comment