//
//  ViewController.swift
//  FireRecord
//
//  Created by victoralissont5@gmail.com on 08/09/2017.
//  Copyright (c) 2017 victoralissont5@gmail.com. All rights reserved.
//

import UIKit
import FireRecord

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        let user = User()
        user.name = "Sanford"
        
        user.save { error in print(error ?? "=)")}
        user.destroy { error in print(error ?? "=)")}
        
        User.findFirst { user in
            print(user.name ?? "Does not contain name")
            user.update(completion: { error in
                print(error ?? "=)")
            })
        }
        User.findLast { user in
            print(user.name ?? "Does not contain name")
        }
        
        User.all { users in
            let names = users.flatMap({$0.name})
            names.forEach({print($0)})
        }
    }
}
class User: FireRecord {
    public var name: String?
    init(name: String) { self.name = name }
    required public init() {}
}




//
//  ViewController.swift
//  FireRecord
//
//  Created by victoralissont5@gmail.com on 08/09/2017.
//  Copyright (c) 2017 victoralissont5@gmail.com. All rights reserved.
//

import UIKit
import FireRecord

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        let user = User()
        user.name = "Correia"
        
        user.save { error in
            print(error ?? "=)")
        }
        user.destroy { error in
            print(error ?? "=)")
        }
        
        User.findFirst { user in
            print(user.name ?? "Does not contain name")
            user.name = "Alisson"
            user.update(completion: { error in
                print(error ?? "=)")
            })
        }
        
        User.all { users in
            let names = users.flatMap({$0.name})
            names.forEach({print($0)})
        }
    }
}
class User: FireRecord {
    public var name: String?
    init(name: String) { self.name = name }
    required public init() {}
}




--- 
+++ 
@@ -14,21 +14,19 @@
     override func viewDidLoad() {
         super.viewDidLoad()
         let user = User()
-        user.name = "Correia"
+        user.name = "Sanford"
         
-        user.save { error in
-            print(error ?? "=)")
-        }
-        user.destroy { error in
-            print(error ?? "=)")
-        }
+        user.save { error in print(error ?? "=)")}
+        user.destroy { error in print(error ?? "=)")}
         
         User.findFirst { user in
             print(user.name ?? "Does not contain name")
-            user.name = "Alisson"
             user.update(completion: { error in
                 print(error ?? "=)")
             })
+        }
+        User.findLast { user in
+            print(user.name ?? "Does not contain name")
         }
         
         User.all { users in
Add more CRUD operation methods in the example
