Guest User

Untitled

a guest
Mar 6th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. func saveImage() {
  2. let documentsDirectoryURL = try! FileManager().url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
  3. let file2ShareURL = documentsDirectoryURL.appendingPathComponent("config.n2kHunt")
  4.  
  5. var json: Any?
  6. let encodedData = try? JSONEncoder().encode(products)
  7. if let data = encodedData {
  8. json = try? JSONSerialization.jsonObject(with: data, options: .allowFragments)
  9. if let json = json {
  10. do {
  11. try String(describing: json).write(to: file2ShareURL, atomically: true, encoding: .utf8)
  12. } catch {
  13. print("unable to write")
  14. }
  15. }
  16. }
  17. }
  18.  
  19. (
  20. {
  21. identity = "blah-1";
  22. major = 245;
  23. minor = 654;
  24. url = "https://web1";
  25. uuid = f54321;
  26. },
  27. {
  28. identity = "blah-2";
  29. major = 543;
  30. minor = 654;
  31. url = "https://web2";
  32. uuid = f6789;
  33. }
  34.  
  35. func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
  36.  
  37. do {
  38. let string2D = try? String(contentsOf: url)
  39. let jsonData = try? JSONSerialization.data(withJSONObject: string2D)
  40. do {
  41. products = try JSONDecoder().decode([BeaconDB].self, from: jsonData!)
  42. } catch let jsonErr {
  43. print("unable to read (jsonErr)")
  44. }
  45.  
  46. } catch {
  47. print("application error")
  48. }
  49. }
Add Comment
Please, Sign In to add comment