Swift NSPREDICATE不像价值

时间:2016-04-18 22:13:56

标签: swift core-data nspredicate

EntityA:体操运动员 名字 lastName的

一对多的MeetResults

EntityB:MeetResults meetDate barScore beamScore floorScore vaultScore

我正在将所有被设置为活跃的体操运动员加载到选择器中。当我创建NSSET result.meetresults = meetScore.copy()为? NSSet工作正常我试图弄清楚如何移除已经拥有NSSET的体操运动员。任何帮助将不胜感激。

func getGymnasts() {

        let fetchRequest = NSFetchRequest(entityName: "Gymnast")

        let sortDescriptor1 = NSSortDescriptor(key: "fullName", ascending: true)

        fetchRequest.sortDescriptors = [sortDescriptor1]

        let filter1 = NSPredicate(format: "isActive == %@", "Yes")

        let filter2 = NSPredicate(format: "ANY meetresults.meetDate != %@", "\(meetDateText.text!)")

        let predicate = NSCompoundPredicate(type: NSCompoundPredicateType.AndPredicateType, subpredicates: [filter1, filter2])

        fetchRequest.predicate = predicate

        //fetchRequest.predicate = filter1

        do {

            self.gymnastArray = try AD.managedObjectContext.executeFetchRequest(fetchRequest) as! [Gymnast]

            self.gymnastPicker.reloadAllComponents()


        } catch {

            fatalError("Fetch Failed")
        }

    }

1 个答案:

答案 0 :(得分:0)

有时候许多关系都很尴尬。您可以使用子查询语法查询内部提取的计数,以查找符合您条件的Meet,然后检查没有:

let filter2 = NSPredicate(format: "SUBQUERY(meetresults.meetDate, $m, $m.meetDate == %@).@count == 0", meetDateText.text!)