gpt4 book ai didi

ios - 自动完成文本字段和 Firebase

转载 作者:行者123 更新时间:2023-11-30 13:01:48 26 4
gpt4 key购买 nike

我正在尝试在 Swift 中集成 Firebase 和 AutoCompleteTextField,以便在 textField 中实现自动完成功能。我在尝试将字典转换为数组以便可以在 autoCompleteTextField.autoCompleteStrings 中设置它时遇到问题。这是我的代码。

func handleTextFieldInterfaces() {

let ref = FIRDatabase.database().reference().child("Airport")
ref.observeEventType(.Value, withBlock: { (snapshot) in
self.autoCompleteTextField.onTextChange = {[weak self] text in

if !text.isEmpty {
var fbosStuff = [String]()
if let snaps = snapshot.value as? [[String: AnyObject]] {
for places in snaps {
print(places)
let names = places["code"] as? String
fbosStuff.append(names!)
}
self!.autoCompleteTextField.autoCompleteStrings = fbosStuff

}
}

}
})
}

我尝试放入文本字​​段的 Firebase 响应是。

Snap (Airport) {
"Long Beach" = {
FBOs = {
Atlantic = {
100LL = "7.0";
freq = "120.1";
fullname = "Atlantic, Long Beach, KLGB";
"jet-A" = "5.5";
"phone number" = "(800) 554-3591";
};
Signature = {
100ll = "7.0";
email = "lgb@signatureflight.com";
freq = "120.1";
fullname = "Signature, Long Beach, KLGB";
"jet-a" = "5.5";
phonenumber = "(800) 554-3591";
};
};
code = KLGB;
fieldname = Daughtery;
location = "Long Beach, California, USA";
};
"Santa Monica" = {
FBOs = {
"American Flyers" = {
100ll = "5.38";
freq = "123.3";
fullname = "American Flyers, Santa Monica, KSMO";
phonenumber = "(310) 390-2099";
};
Atlantic = {
100ll = "7.79";
freq = "122.95";
fullname = "Atlantic, Santa Monica, KSMO";
"jet-a" = "7.19";
phonenumber = "(310) 396-6770";
};
};
code = KSMO;
fieldname = "Santa Monica Muni Airport";
location = "Santa Monica, California, USA";
};

}

最佳答案

尝试:-

swift 2

for places in snaps {

print(places.0) // Will give you the key
let names = places["code"] as? String
fbosStuff.append(names!)

}

swift 3

for places in snaps {

print(places.key) // Will give you the key
let names = places["code"] as? String
fbosStuff.append(names!)

}

关于ios - 自动完成文本字段和 Firebase,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39838688/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com