iOS - Swift - 使用数组和条件循环

标签 ios arrays swift for-loop conditional-statements

我想在一个数组上做一个循环,但想在一个条件后停止。这就是我现在所拥有的(顺便说一句,我正在使用 Parse 作为后端)。

let query = PFQuery(className: "MyObject")
query.whereKey("user", equalTo: PFUser.currentUser())
query.findObjectsInBackgroundWithBlock { (objects:[AnyObject]!, error:NSError!) -> Void in
        if error == nil {
            for object in objects {
                print(object.objectId)
            }
        }
}

此代码正在打印每个 objectId。

现在假设我想打印每个对象直到我找到一个objectId == "xxx"的对象。

我应该怎么做?

最佳答案

如果你想过滤objId并执行一些代码:

let array = ["id1", "id2", "id3", "id4"]
for objId in array where objId != "id3" {
    print(objId)
}

关于iOS - Swift - 使用数组和条件循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33394626/

相关文章:

ios - 如何使用 Objective C 增加 UItableView 中的 UIView 高度?

javascript - 循环遍历整个数组 - 所有索引

ios - managedObjectContext 不能多次使用?

ios - 构建分离到库和应用程序部分的应用程序时,框架 undefined symbol

ios - Xcode 调试 View 层次结构显示空白屏幕

JavaScript 二维数组

c# - 安全访问 MemoryStream 中的数据

ios - 在SpriteKit中使用UIInterpolatingMotionEffect?

ios - Swift 包括 JustHTTP/Just 构建失败

ios - Swinject:迁移到程序集