最終プロジェクトにFirebaseを使用するリスクがありました。 Firebaseデータベースからデータを取得できません。私はどこが間違っているのか分かりません。私を教えてください。FirebaseデータベーススウィフトでJSONからデータを取得できません
メインファイル:
var ref: FIRDatabaseReference!
let user = FIRAuth.auth()?.currentUser
@IBOutlet var placename: UILabel!
@IBOutlet var placetype: UILabel!
var SiasuObj = [siasuObj]()
var PlaceObj = [placeObj]()
var planPriceLevel = ""
override func viewDidLoad() {
super.viewDidLoad()
fetchData()
findPlaceToEat()
}
func fetchData(){
//var planPriceLevel = ""
ref = FIRDatabase.database().reference()
//I can't pass through this part
ref.child("ios_entry").child(user!.uid).child("Budget").observeEventType(.ChildAdded, withBlock: {
(snapshot) in
if let dictionary = snapshot.value as? [String: AnyObject]{
let SiasuObj = siasuObj()
SiasuObj.setValuesForKeysWithDictionary(dictionary)
self.SiasuObj.append(SiasuObj)
print("Total budget")
print(SiasuObj.total_budget, SiasuObj.total_day, SiasuObj.total_pax)
SiasuObj.total_budget = dictionary ["total_budget"] as! String
SiasuObj.total_day = dictionary["total_day"] as! String
SiasuObj.total_pax = dictionary["total_pax"] as! String
let total_budget:Int32? = Int32(SiasuObj.total_budget);
print(total_budget)
let total_day:Int32? = Int32(SiasuObj.total_day);
print(total_day)
let total_pax:Int32? = Int32(SiasuObj.total_pax);
print(total_pax)
let budgetPerPax = (total_budget!/total_pax!)/(total_day! * 3);
if(budgetPerPax < 50){
self.planPriceLevel = "1";
self.findPlaceToEat();
}else if(budgetPerPax <= 150){
self.planPriceLevel = "2";
self.findPlaceToEat();
}else if(budgetPerPax > 150){
self.planPriceLevel = "3";
self.findPlaceToEat();
}
}
}, withCancelBlock: nil)
}
func findPlaceToEat(){
print("inside findPlaceToEat()")
print("Plan price level")
print(planPriceLevel)
//let pricelevel = String(planPriceLevel)
// print("pricelevel")
//print(pricelevel)
ref.child("places_detail").child("price_level").child(planPriceLevel).childByAutoId().observeEventType(.ChildAdded, withBlock:{
(snapshot) in
if let dictionary = snapshot.value as? [String: AnyObject]{
let PlaceObj = placeObj()
//placeObj.setValuesForKeysWithDictionary(dictionary)
//self.PlaceObj.append(PlaceObj)
print("Whatever")
print(PlaceObj.place_name, PlaceObj.place_type)
PlaceObj.place_name = dictionary["place_name"] as! String
PlaceObj.place_type = dictionary["place_type"] as! String
PlaceObj.price_range = dictionary["price_range"] as! String
PlaceObj.vegan_type = dictionary["vegan_type"] as! String
PlaceObj.website = dictionary["website"] as! String
self.placename.text = PlaceObj.place_name;
}
}, withCancelBlock: nil)
}
クラスファイル:
class placeObj: NSObject {
var place_name : String!
var place_type : String!
var price_range : String!
var vegan_type : String!
var website : String!
}
firebaseの構造を投稿してください。 –