Tag: 收集

基本的数组比较algorithm

我试图按照这里find的步骤比较两个数组,并知道什么时候创build一个新的对象,但我只是不明白它是如何工作的: 您最终得到两个sorting数组 – 一个是传递给获取请求的员工ID,另一个是与他们匹配的pipe理对象。 要处理它们,请按以下步骤执行sorting的列表: Get the next ID and Employee. If the ID doesn't match the Employee ID, create a new Employee for that ID. Get the next Employee: if the IDs match, move to the next ID and Employee. 无论您传入多less个ID,您只执行一次提取,其余的只是执行结果集。 基本上发生了什么事情是我有一个来自外部来源的对象ID数组,客户端系统只有这些ID表示的对象的子集。 我需要弄清楚我已经拥有了哪些物品,如果我没有这些物品,请逐个创build它们。 我不明白这是如何工作的。 我很难将其翻译成代码: for (int i =0;i<ids.count;i++) { currentId = [ids objectAtIndex:i]; […]

executeFetchRequest抛出致命错误:NSArray元素无法匹配Swift数组元素types

我正在用CoreDatatestingswift,并创build了以下代码: import UIKit import CoreData class Contact: NSManagedObject { @NSManaged var name: String @NSManaged var email: String class func execute(){ let appDel:AppDelegate = (UIApplication.sharedApplication().delegate as AppDelegate) let context:NSManagedObjectContext = appDel.managedObjectContext! let entityDescripition = NSEntityDescription.entityForName("Contact", inManagedObjectContext: context) let contact = Contact(entity: entityDescripition!, insertIntoManagedObjectContext: context) contact.name = "john Apleesee" contact.email = "john@apple.com" context.save(nil) let fetch:NSFetchRequest = NSFetchRequest(entityName: […]