Попытка выяснить, почему иногда это происходит в swift / Xcode.Когда я проверяю "employee.isEmpty", возвращается правильно, потому что он пуст.Когда проверяется «uids.isEmpty», он также возвращает пустое значение, но по какой-то причине он думает, что есть значения, а затем выполняет мой вызов firebase, который, конечно, завершает работу приложения, поскольку массив равен нулю.Почему это происходит?Тот же кодТо же самое.И все же «employee.isEmpty» возвращает nil, как и должно быть (в моем тестировании), а другой «uids.isEmpty» пуст, но выполняется так, как если есть значения, а их нет.
if employees.isEmpty == false {
print("This shouldnt be called 1")
OneSignal.postNotification(["contents": ["en": "\(message)"],
"include_player_ids": employees,
"headings": ["en": "Hey \(businessName)"],
"ios_badgeType": "Increase",
"ios_badgeCount": 1])
} else {
print("Empty no execution")
}
print(employees)
print("Checking inside employees here")
print(uids)
print("Checking inside uids here")
if uids.isEmpty == false {
print("This shouldnt be called 2")
let pathing = ref.child("notification").child(uids).childByAutoId()
pathing.setValue(values)
} else {
print("Empty no execution")
}
Они оба печатают одинаково, когда не назначено никаких значений, например: «[]».
Декларации / Приложение
var data:[String] = []
var dataUID:[String] = []
// GETTING THE ONESIGNAL ID'S FROM THE EMPLOYEES FOR NOTIFICATIONS
func getEmployees() {
Database.database().reference().child("Businesses").child(self.otherUser?["uid"] as! String).child("registered_employees").observe(.childAdded, with: { (snapshot) in
if snapshot.exists() {
let data = snapshot.value as? NSDictionary
let uid = data?["onesignal"] as? String
self.data.append(uid!)
print(self.data)
} else {
print("didnt call right values")
}
})
}
func getEmployeesUIDs() {
Database.database().reference().child("Businesses").child(self.otherUser?["uid"] as! String).child("registered_employees").observe(.value, with: { (snapshot) in
if snapshot.exists() {
let data = snapshot.value as? NSDictionary
let uid = data?["uid"] as? String
self.dataUID.append(uid!)
print(self.dataUID)
print("Printing the employee uids right here")
} else {
print("didnt call right values")
}
})
}
let employees = self.data
let uids = self.dataUID.description
if employees.isEmpty {
print("Empty no execution")
} else {
print("This shouldnt be called 1")
OneSignal.postNotification(["contents": ["en": "\(message)"],
"include_player_ids": employees,
"headings": ["en": "Hey \(businessName)"],
"ios_badgeType": "Increase",
"ios_badgeCount": 1])
}
print(employees)
print("Checking inside employees here")
print(uids)
print("Checking inside uids here")
if uids.isEmpty {
print("Empty no execution")
} else {
print("This shouldnt be called 2")
let pathing = ref.child("notification").child(uids).childByAutoId()
pathing.setValue(values)
}