Skip to content
This repository has been archived by the owner on Aug 25, 2018. It is now read-only.

Commit

Permalink
Removing view when value is null, not when child gets removed.
Browse files Browse the repository at this point in the history
  • Loading branch information
katfang committed Mar 3, 2015
1 parent 6415387 commit 627365c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 11 deletions.
3 changes: 0 additions & 3 deletions ios/OfficeMover5000/OfficeMover5000/Furniture.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,15 @@ class Furniture {
let defaultLoc = Furniture.defaultLocation(self.type)
self.top = defaultLoc.top
self.left = defaultLoc.left

}

convenience init(snap: FDataSnapshot) {

if let json = snap.value as? Dictionary<String, AnyObject> {
self.init(key: snap.key, json: json)
}
else {
fatalError("blah")
}

}

func toJson() -> Dictionary<String, AnyObject> {
Expand Down
11 changes: 3 additions & 8 deletions ios/OfficeMover5000/OfficeMover5000/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class ViewController: RoomViewController {
// Load the furniture items from Firebase
furnitureRef.observeEventType(.ChildAdded, withBlock: { [unowned self] snapshot in
self.refLocations += ["furniture/\(snapshot.key)"]
println("Furniture! \(snapshot)")
let furniture = Furniture(snap: snapshot)
self.createFurnitureView(furniture)
})
Expand All @@ -44,18 +43,14 @@ class ViewController: RoomViewController {

// move the view from a remote update
currentFurnitureRef.observeEventType(.Value, withBlock: { snapshot in
// check if snapshot.value does not equal NSNull
if snapshot.value as? NSNull != NSNull() {
if snapshot.exists() {
let furniture = Furniture(snap: snapshot)
view.setViewState(furniture)
} else {
view.delete()
}
})

// delete the view from remote update
currentFurnitureRef.observeEventType(.ChildRemoved, withBlock: { snapshot in
view.delete()
})


// When the furniture moves, update the Firebase
view.moveHandler = { top, left in
Expand Down

0 comments on commit 627365c

Please sign in to comment.