Posts

Showing posts with the label core-data

Class implemented in app target and test target

Image
Clash Royale CLAN TAG #URR8PPP Class implemented in app target and test target I'm using CoreData and have extended the automatic (didn't generate custom class files) model classes by custom variables that return objects of classes coming from an CocoaPods dependency. import Foundation import ACocoaPodsFramework import CoreData extension MyClass { var customVar: AClassFromCocoaPods? { return AClassFromCocoaPods() } } I've added a target for unit tests to the Xcode project and added MyClass to the test target. A test class looks like the following. import XCTest import ACocoaPodsFramework import CoreData @testable import MyAppTarget class MyClassTests: XCTestCase { } I have imported ACocoaPodsFramework in both the app and the unit test target as a framework. When i run the unit tests i receive the following notice objc[21178]: Class MyClass is implemented in both /.../MyAppTarget.app/MyAppTarget (0x1017703f0) and /... MyAppTarget.app/PlugIns/MyClassTests.xcte...

FetchedResultsController Using Predicate to Exclude Results Contained in a Set

Image
Clash Royale CLAN TAG #URR8PPP FetchedResultsController Using Predicate to Exclude Results Contained in a Set I am attempting to filter the items in my FetchedResultsController to filter out a certain set of items. These are engines which have a certain letter designation in them followed by numbers. The possible rage of letters in the designation are from "A" to "O". I would like to be able to filter out engines that have the designations from "D" to "O" based on another condition. I set a constant "highPowerEngines" that is a set containing those letters. Since the designation only contains one letter, I want to exclude any designation that contains any of the letters in highPowerEngines. So far, this is my code, the predicate I am working on is contained after the FIXME: func configureFetchedResultsController() { let context = databaseController.getContext() let enginesFetchRequest = NSFetchRequest<Engine>(entityName: C...

Cannot fetch the entries of core data

Image
Clash Royale CLAN TAG #URR8PPP Cannot fetch the entries of core data I have below code that it will populate the core database with entries from struct array. When I debug it seems that is sending correctly the data to the func iterateCoreData, but when I try to fetch the result I don't get anything. What it could possible be wrong that either not add the data to database or couldn't fetch them. I have tried the main syntax of saving and fetching with a plain array it works correctly. let managedObjectContext = self.persistentContainer.viewContext // this is the working method to save data to core data and then fetch it. /* guard let entity = NSEntityDescription.entity(forEntityName: "Journal", in: managedObjectContext) else { fatalError("There is no such entity!") } for id in journalNoteArray.id { let data = NSManagedObject(entity: entity, insertInto: man...