@IBAction func one_2(sender: AnyObject) {
if un_1.textColor == UIColor.blueColor() {
if aac == false {
var aa = [FIRDataSnapshot]()
DataService.ds.REF_ISSUELIKES.observeEventType(.Value, withBlock: { (snapshot) in
if let snapshots = snapshot.children.allObjects as? [FIRDataSnapshot] {
for snap in snapshots {
aa.append(snap)
}
print(aa[0])
var aaUpvotes = String()
var aaDownvotes = String()
let a = Array(String(aa[0]).characters)
if a.count == 55 {
aaUpvotes = String(a[51])
aaDownvotes = String(a[34])
} else if a.count == 57 {
aaDownvotes = String("\(a[34])\(a[35])")
aaUpvotes = String("\(a[52])\(a[53])")
} else if a.count == 59 {
aaDownvotes = String("\(a[34])\(a[35])\(a[36])")
aaUpvotes = String("\(a[53])\(a[54])\(a[55])")
}
self.ref.child("IssueLikes").child("Abortion").child("Upvotes").setValue(Int(aaUpvotes)! + 1)
self.ref.child("IssueLikes").child("Abortion").child("Downvotes").setValue(Int(aaDownvotes)! - 1)
}
})
aab = false
un_1.text = String(Int(un_1.text!)!-1)
un_2.text = String(Int(un_2.text!)!+1)
un_1.textColor = UIColor.whiteColor()
un_2.textColor = UIColor.blueColor()
aac = true
} else {
print("AAC")
}
} else if un_1.textColor == UIColor.whiteColor() {
if aac == false {
var aa = [FIRDataSnapshot]()
DataService.ds.REF_ISSUELIKES.observeEventType(.Value, withBlock: { (snapshot) in
if let snapshots = snapshot.children.allObjects as? [FIRDataSnapshot] {
for snap in snapshots {
aa.append(snap)
}
print(aa[0])
var aaUpvotes = String()
var aaDownvotes = String()
let a = Array(String(aa[0]).characters)
if a.count == 55 {
aaUpvotes = String(a[51])
aaDownvotes = String(a[34])
} else if a.count == 57 {
aaDownvotes = String("\(a[34])\(a[35])")
aaUpvotes = String("\(a[52])\(a[53])")
} else if a.count == 59 {
aaDownvotes = String("\(a[34])\(a[35])\(a[36])")
aaUpvotes = String("\(a[53])\(a[54])\(a[55])")
}
self.ref.child("IssueLikes").child("Abortion").child("Upvotes").setValue(Int(aaUpvotes)! + 1)
}
})
aab = false
un_2.textColor = UIColor.blueColor()
un_2.text = String(Int(un_2.text!)!+1)
aac = true
} else {
print("AAC")
}
} else {
if aac == false {
var aa = [FIRDataSnapshot]()
DataService.ds.REF_ISSUELIKES.observeEventType(.Value, withBlock: { (snapshot) in
if let snapshots = snapshot.children.allObjects as? [FIRDataSnapshot] {
for snap in snapshots {
aa.append(snap)
}
print(aa[0])
var aaUpvotes = String()
var aaDownvotes = String()
let a = Array(String(aa[0]).characters)
if a.count == 55 {
aaUpvotes = String(a[51])
aaDownvotes = String(a[34])
} else if a.count == 57 {
aaDownvotes = String("\(a[34])\(a[35])")
aaUpvotes = String("\(a[52])\(a[53])")
} else if a.count == 59 {
aaDownvotes = String("\(a[34])\(a[35])\(a[36])")
aaUpvotes = String("\(a[53])\(a[54])\(a[55])")
}
self.ref.child("IssueLikes").child("Abortion").child("Upvotes").setValue(Int(aaUpvotes)! + 1)
}
})
aab = false
un_1.textColor = UIColor.whiteColor()
un_2.textColor = UIColor.whiteColor()
un_2.text = String(Int(un_2.text!)!+1)
un_2.textColor = UIColor.blueColor()
aac = true
} else {
print("AAC")
}
}
}
내 코드에서 알 수 있듯이 버튼을 클릭하면 Firebase를 새로운 값으로 업데이트하려고합니다. 그러나 이러한 버튼을 클릭하면 데이터베이스의 Firebase 값이 1 밀리 초마다 1에서 0으로 변경됩니다.Firebase 빠른 데이터로 데이터 가져 오기
나는 여러 번 내 코드를 검사 한 결과 아무 것도 잘못 찾을 수 없습니다. 어떤 도움이라도 대단히 감사합니다.
아, 그건 도움이됩니다. 비밀 식별자 이름에 관해서는 큰 응용 프로그램입니다. 실제로 모든 것을 말하면 체계적인 방법입니다. 고마워. –