SHARE
TWEET

Untitled

a guest Jul 17th, 2017 36 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. PFUser.current()?.saveInBackground(block: { [weak self] (success, error) in
  2.             if let error = error {
  3.                 Log.error?.message(error.localizedDescription)
  4.                 return
  5.             }
  6.             guard let sessionToken = PFUser.current()?.sessionToken else {
  7.                 Log.error?.message("Did not get session token even after saving user")
  8.                 return
  9.             }
  10.         })
  11.    
  12. class ParseHelper {    
  13.     var parsePrivateDocumentsDirectory: URL? {
  14.         let filemanager = FileManager.default
  15.         guard let libraryDirectory = filemanager.urls(for: .libraryDirectory, in: .userDomainMask).last else {
  16.             return nil
  17.         }
  18.  
  19.         guard let parseDirectory = URL(string: "Private%20Documents/Parse/", relativeTo: libraryDirectory) else {
  20.             return nil
  21.         }
  22.         return parseDirectory
  23.     }
  24.  
  25.     func parseFile(_ filename: String) -> URL? {
  26.         let filemanager = FileManager.default
  27.         guard let parseDirectory = self.parsePrivateDocumentsDirectory else {
  28.             return nil
  29.         }
  30.  
  31.         guard let installationIdUrl = URL(string: filename, relativeTo: parseDirectory) else {
  32.             return nil
  33.         }
  34.  
  35.         if filemanager.fileExists(atPath: installationIdUrl.path) {
  36.             return installationIdUrl
  37.         } else {
  38.             return nil
  39.         }
  40.     }
  41.  
  42.     var installationId: String? {
  43.         guard let fileURL = self.parseFile("installationId"), let data = try? Data(contentsOf: fileURL) else {
  44.             return nil
  45.         }
  46.         let string = String(data: data, encoding: String.Encoding.utf8)
  47.         return string
  48.     }
  49.  
  50.     var applicationId: String? {
  51.         guard let fileURL = self.parseFile("applicationId"), let data = try? Data(contentsOf: fileURL) else {
  52.             return nil
  53.         }
  54.         let string = String(data: data, encoding: String.Encoding.utf8)
  55.         return string
  56.     }
  57.  
  58.     var config: String? {
  59.         guard let fileURL = self.parseFile("config"), let data = try? Data(contentsOf: fileURL) else {
  60.             return nil
  61.         }
  62.         let string = String(data: data, encoding: String.Encoding.utf8)
  63.         return string
  64.     }
  65. }
RAW Paste Data
Top