ios - PFObject 无法与匹配的 TextField 字符串(Parse、Swift、iOS、Xcode 7 Beta)一起正常工作

标签 ios swift parse-platform pfquery pfobject

我的主要目标是让用户在 TextField 中输入一个邮政编码,然后解析将检查数据库,看看该邮政编码是否与数据库中的邮政编码匹配。如果是,它将允许用户注册并发送 println("youre in.")。 如果不是,它会打印(“你出去了”)

这是我当前的代码,以及我的 Parse 后端的样子。

class checkAvailability: UIViewController, UITextFieldDelegate {

@IBOutlet weak var zipCode: UITextField!
@IBAction func checkAvailBtn(sender: AnyObject) {
    checkZip()
}

func checkZip() {
    let usersZipCode = zipCode.text
    let query = PFQuery(className:"zipCodes")
    query.findObjectsInBackgroundWithBlock {
        (objects: [AnyObject]?, error: NSError?) -> Void in

        if error == nil {
            // The find succeeded.
            print("Successfully retrieved \(objects!.count) zip codes.", terminator: "")
            // Do something with the found objects
            if let zipCodes = objects! as? [PFObject] {
                if zipCodes.contains({ $0["zipCodes"] as? String == usersZipCode }) {
                    print("your in!") // transition to the new screen

                }
                else {
                    print("your out.") // do whatever
                }
            }
        } else {
            // Log details of the failure
            print("Error: \(error!) \(error!.userInfo)", terminator: "")
        }
    }
}





override func viewDidLoad() {
    super.viewDidLoad()
    self.zipCode.delegate=self;
}
    //Allow only numbers
    func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool {
        return Int(string) != nil
    }



//Display Navbar
override func viewWillAppear(animated: Bool)
{
    self.navigationController?.navigationBarHidden = false
}

 }

这是我的数据库的图像:enter image description here

最佳答案

我想通了,我数据库中的每个条目都有一个“;”在邮政编码之后。这就是输入被错误读取且无法正常工作的原因。

关于ios - PFObject 无法与匹配的 TextField 字符串(Parse、Swift、iOS、Xcode 7 Beta)一起正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32402876/

相关文章:

parse-platform - 解析 - 安装表未设置 deviceToken 或 pushType

ios - 确定网络可用性

android - 自定义通过解析收到的通知

ios - 上拉菜单的用户界面类别是什么?

ios - 哪个函数用于获取 DJI Drone for iOS 的 GPS 坐标的确切位置

ios - 如何使用 Firebase Web 将链接中的图像保存到 Firebase 存储?

ios - 完成的 Firebase 嵌套查询

swift - 你能在 Swift 中重载类型转换运算符吗?

ios - 来电消失查看事件

ios - 带有德语变音符号的 NSJSONSerialization 异常