1
解析問題我在行面臨的問題火力地堡數據,讓用戶=用戶(快照:代碼FIRDataSnapshot)當我用考取到我的模型類之前打印的代碼值是這樣的:在SWIFT 3.0
Snap (p5ZmlWTnZuWmCUFIS3KEVFCwoaB2) {
addressLine = "K-03";
bookingPayment = {
bookingPayment1474215359 = {
cardType = Visa;
date = "19/09/2016";
duration = 1;
expirationDate = "12/2020";
facilityId = facility1474021328102;
facilityName = "Conference Hall";
fromDate = "20/09/2016";
fromTime = "6:32 AM";
id = bookingPayment1474215359;
imageUrl = 「www.google.com」;
issuingBank = Unknown;
last4 = 1881;
paidAmount = 200;
time = "12:15 AM";
toDate = "20/09/2016";
toTime = "7:32 AM";
uid = p5ZmlWTnZuWmCUFIS3KEVFCwoaB2;
};
bookingPayment1474215539 = {
cardType = Visa;
date = "19/09/2016";
duration = 1;
expirationDate = "12/2020";
facilityId = facility1474021328102;
facilityName = "Conference Hall";
fromDate = "20/09/2016";
fromTime = "7:32 AM";
id = bookingPayment1474215539;
imageUrl = 「www.google.com」;
issuingBank = Unknown;
last4 = 1881;
paidAmount = 200;
time = "12:18 AM";
toDate = "20/09/2016";
toTime = "8:32 AM";
uid = p5ZmlWTnZuWmCUFIS3KEVFCwoaB2;
};
};
checkedIn = 1;
email = 「[email protected]";
name = 「abcd";
notificationPreference = {
bus = 1;
foodDelivery = 1;
garbageCollector = 1;
postman = 1;
taxi = 1;
};
password = 123456;
phone = 0174802580;
playerId = "95eab868-8c80-47cc-b22a-cd8c07c8a258";
status = SOS;
timestamp = 1474444615518;
uid = p5ZmlWTnZuWmCUFIS3KEVFCwoaB2;
uniqueCode = IT3VXAALSAQ8M;
url = "";
visitor = {
"visitor20160921_142054" = {
arriveGuardId = guard1473917758421;
arriveTimestamp = 1474438855260;
carPlate = Djjdjsfn;
departGuardId = guard1473917758421;
departTimestamp = 1474440472751;
ic = Lellss;
id = "visitor20160921_142054";
late = 0;
name = Bick;
pendingDepartTimestamp = 1474439100035;
phone = JFKd;
residentUid = p5ZmlWTnZuWmCUFIS3KEVFCwoaB2;
status = History;
visitingTimestamp = 1474438914243;
};
"visitor20160921_142312" = {
arriveGuardId = guard1473917758421;
arriveTimestamp = 1474438994041;
carPlate = Djjdjsfn;
departTimestamp = 0;
ic = Lellss;
id = "visitor20160921_142312";
late = 0;
name = 244;
pendingDepartTimestamp = 0;
phone = JFKd;
residentUid = p5ZmlWTnZuWmCUFIS3KEVFCwoaB2;
status = Visiting;
visitingTimestamp = 1474439014801;
};
"visitor20160921_144804" = {
arriveGuardId = guard1473917758421;
arriveTimestamp = 1474440485858;
carPlate = Djjdjsfn;
departTimestamp = 0;
ic = Lellss;
id = "visitor20160921_144804";
late = 0;
name = Bick;
pendingDepartTimestamp = 0;
phone = JFKd;
residentUid = p5ZmlWTnZuWmCUFIS3KEVFCwoaB2;
status = Visiting;
visitingTimestamp = 1474441499543;
};
"visitor20160921_155225" = {
arriveGuardId = guard1473917758421;
arriveTimestamp = 1474444346180;
carPlate = Ajx4563;
departGuardId = guard1473917758421;
departTimestamp = 1474444514132;
ic = 9102827182910;
id = "visitor20160921_155225";
late = 0;
name = Nick;
pendingDepartTimestamp = 1474444476399;
phone = 0174802580;
residentUid = p5ZmlWTnZuWmCUFIS3KEVFCwoaB2;
status = History;
visitingTimestamp = 1474444388517;
};
};
}
func getData() {
reference_user.observe(.value, with: { snapshot in
var userData: [Users] = []
for code in snapshot.children {
print(code)
**let user = Users(snapshot: code as! FIRDataSnapshot)**
print(user)
}
})
}
和解析用戶的價值之後。當我打印它給this.Means befor解析位訪客有4個記錄的用戶,但分析之後它給我的只有第一record.Here是
Users(key: "p5ZmlWTnZuWmCUFIS3KEVFCwoaB2",
name: "abcd",
email: "[email protected]",
password: "123456",
phone: "0174802580",
unit: "",
uniqueCode: "IT3VXAALSAQ8M",
status: "SOS",
checkedIn: true,
accountStatus: "",
accountType: "",
addressLine: "K-03",
playerId: "95eab868-8c80-47cc-b22a-cd8c07c8a258",
signUpTimestamp: 0,
uid: "p5ZmlWTnZuWmCUFIS3KEVFCwoaB2",
notificationPreference: {
bus = 1;
foodDelivery = 1;
garbageCollector = 1;
postman = 1;
taxi = 1;
},
visitor: Optional(Appname.UserVisitor(username: Optional("Bick"),
userstatus: Optional("History"),
userdepartTimestamp: 1474440472751,
arriveGuardId: "guard1473917758421",
arriveTimestamp: 1474438855260,
carPlate: "Djjdjsfn",
ic: "Lellss",
phone: "JFKd",
visitor_id:
"visitor20160921_142054")),
ref: https://appname.firebaseio.com/user/p5ZmlWTnZuWmCUFIS3KEVFCwoaB2)
你可以添加你的'用戶'類嗎? – ronatory