-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ObjectMapper + Firebase? #398
Comments
Sorry I have never used or heard of Firebase so I do not have any samples to tutorials for you. |
@tristanhimmelman if you don't know Firebase you can check this: Firebase features 😉
With Firebase we manage NSDictionary and NSArray that I need to map to internal classes. |
I'm interesting the same thing. |
Found it! 😀 Example with an Array of usersJsonImport this Json at {
"Users": [
{
"firstName": "Paul",
"lastName": "Dumont"
},
{
"firstName": "Jacque",
"lastName": "Zero"
},
{
"firstName": "Marc",
"lastName": "Longshot"
}
]
} ObjectMapper classimport Foundation
import ObjectMapper
class User: Mappable {
var firstName:String? = nil
var lastName:String? = nil
required init?(_ pMap: Map){
}
func mapping(pMap: Map) {
self.firstName <- pMap["firstName"]
self.lastName <- pMap["lastName"]
}
} View ControllerReplace import UIKit
import Firebase
import ObjectMapper
class FirebaseViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let lUsers = Firebase(url: "https://<your db>.firebaseio.com/Users")
lUsers.observeEventType(.Value) {
(pSnapshot:FDataSnapshot!) -> Void in
if let lJsonArray = pSnapshot.value as? [[String : AnyObject]] {
let lUsers = Mapper<User>().mapArray(lJsonArray)
print("\(lUsers)")
}
}
}
} Debug view |
Thanks 😄 |
Maybe this is helpful to someone, I ended up creating a mix of many resources on the Internet. `
} you only need to inherit from it: `
} and an example of use:
|
@omarzl nice code you got there |
nice sharing |
Very thanks ! |
@omarzl great way to deal with mapping |
Is there any way we can convert firebase snapshot object to raw json ? Then it could be easy to convert to this. Anythoughts ? Would like to if anyone has searlized snapshot object to JSON and using the mapper - are there any underlying implications of it ? |
Hi
How I can use ObjectMapper with Firebase?
Do you have any tutorials or samples?
The text was updated successfully, but these errors were encountered: