iOS CoreData fails to fetch data <p>I am developing an application for iOS which has .xcdatamodeld file with a couple of entities, one of which is UserInfo with an attribute "name" of type <code>String</code>. Now that I am on stage of developing I don't always get entities fetched (I rarely do) and therefore I've got a question: Does that mean I have a problem or is it normal for "Test Flights"? This also happens if I open an app, which stays installed after the last test and test its ability to keep data.</p> <p>Here is how I handle data for this particular entity:</p> <pre><code>private func fetchData(){ let fetch = NSFetchRequest(entityName: entityName) var entities = [UserInfo]() do { entities = try moc.executeFetchRequest(fetch) as! [UserInfo] }catch{ delegate.currVC.showSystemMessage("Failed to execute data for \(fetch.entityName!) fetch request", ofType: .ERROR) } if entities.count &gt; 0{ print("Entities found: \(entities.count)") let last = entities.first! name = last.name } } func saveData(){ let fetch = NSFetchRequest(entityName: entityName) var entities = [UserInfo]() do { entities = try moc.executeFetchRequest(fetch) as! [UserInfo] }catch{ delegate.currVC.showSystemMessage("Failed to execute data for \(fetch.entityName!) fetch request", ofType: .ERROR) } if entities.count &gt; 0{ let last = entities[0] last.name = name do{ try moc.save() }catch{ delegate.currVC.showSystemMessage("An error occured while trying to save user data", ofType: .ERROR) } }else{ let entity = NSEntityDescription.insertNewObjectForEntityForName(entityName, inManagedObjectContext: moc) as! UserInfo entity.setValue(name, forKey: "name") do{ try moc.save() }catch{ delegate.currVC.showSystemMessage("Failed to save name to CoreData", ofType: .ERROR) } } } </code></pre> <p>Notes: <code>moc</code> is an <code>NSManagedObjectContext</code> which I keep as a constant in delegate and only initialize once. <code>showSystemMessage</code> is a custom method, which, by the way, is never triggered by this method (which means nothing's caught inside of this whole method).</p> <p>My assumptions are that this might be happening because <code>executeFetchRequest</code> is executed in a new Thread and therefore sometimes fails to fetch data before it's returned, but, yet again, I have no idea if it is so or not. Anyway, I really am looking forward to solving this issue with your help, since it is crucial for my app to have an ability to keep data. Thank you in advance!</p>