传递给Core Data中的setPropertiesToFetch的无效密钥路径

时间:2016-06-30 09:59:34

标签: xcode swift core-data

使用setPropertiesToFetch时出现此错误。这很奇怪,因为info1和info2确实存在于我的实体中。

    let fetchRequest = NSFetchRequest()
    let entityDescription = NSEntityDescription.entityForName("Table1", inManagedObjectContext: managedObjectContext)
    fetchRequest.resultType = .DictionaryResultType
    fetchRequest.returnsDistinctResults = true

    fetchRequest.propertiesToFetch = ["info1", "info2"]
    fetchRequest.includesSubentities = true
    fetchRequest.entity = entityDescription

    do {
        let result = try managedObjectContext.executeFetchRequest(fetchRequest)

        print(result)

    } catch {
        let fetchError = error as NSError
        print(fetchError)
    }

没有propertiesToFetch行,我得到了这个输出:

[{
    info1 = data1;
    info2 = data2;
    info3 = data3;
}, { 
...
}]

1 个答案:

答案 0 :(得分:4)

在使用/********************************************************* * Function: OpenBrowser() **********************************************************/ public static void openApp(String browserName, String env) throws Exception{ driver = BrowserFactory.getBrowser(browserName); Log.info("Browser:" + browserName); driver.manage().window().maximize(); driver.get(env); Log.info("Env: " + env); waitForObj.wait(1); } public class BrowserFactory { private static Map<String, WebDriver drivers = new HashMap<String, WebDriver>(); /* * Factory method for getting browsers */ public static WebDriver getBrowser(String browserName) { WebDriver driver = null; switch (browserName) { case "Firefox": driver = drivers.get("Firefox"); if (driver == null) { driver = new FirefoxDriver(); drivers.put("Firefox", driver); } break; case "IE": driver = drivers.get("IE"); if (driver == null) { System.setProperty("webdriver.ie.driver", SystemUtils.getUserDir() + "\\drivers\\IEDriverServer.exe"); driver = new InternetExplorerDriver(); drivers.put("IE", driver); } break; case "Chrome": driver = drivers.get("Chrome"); if (driver == null) { System.out.println(SystemUtils.getUserDir()); System.setProperty("webdriver.chrome.driver",SystemUtils.getUserDir() + "\\drivers\\chromedriver.exe"); driver = new ChromeDriver(); drivers.put("Chrome", driver); } break; } return driver; } 之前需要设置实体。

propertiesToFetch