Can I apply multiple predicates to an NSFetchRequest? Would it be better to manually parse my results?

Yes it’s possible. You’re looking for compound predicates and here’s an example with AND predicates: NSPredicate *compoundPredicate = [NSCompoundPredicate andPredicateWithSubpredicates:[NSArray of Predicates]]; You can also use notPredicateWithSubpredicates and orPredicateWithSubpredicates depending on your needs. Link to documentation https://developer.apple.com/documentation/foundation/nscompoundpredicate

Deleting all data in a Core Data entity in Swift 3

You’re thinking of NSBatchDeleteRequest, which was added in iOS 9. Create one like this: let fetch = NSFetchRequest<NSFetchRequestResult>(entityName: “Employee”) let request = NSBatchDeleteRequest(fetchRequest: fetch) You can also add a predicate if you only wanted to delete instances that match the predicate. To run the request: let result = try managedObjectContext.executeRequest(request) Note that batch requests don’t … Read more

How to access CoreData model in today extension (iOS)

What you really want is to access your persistent store (most likely a SQLite database). In order to achieve that, you need to configure App Groups and make sure that your host app configures the Core Data stack using your shared container (so your store is accessible in extension as well). Something like: NSString *containerPath … Read more

How can I find out if the iPhone user currently has a passcode set and encryption enabled?

Disclaimer: This answer was valid until ios 4.3.3 If data protection is turned on, a newly created file will have a nil NSFileProtectionKey by default. If data protection is turned off, a newly created file will have a NSFileProtectionNone NSFileProtectionKey by default. Thus, you could detect the presence of file protection with the following code: … Read more

Is it possible to override getters and setters for @dynamic properties in an NSManagedObject subclass?

Never call [super valueForKey:..] in a NSManagedObject subclass! (unless you implemented them in a superclass yourself) Instead use the primitive accessor methods. Sample getter/setter implementation from ADC: @interface Department : NSManagedObject @property(nonatomic, strong) NSString *name; @end @interface Department (PrimitiveAccessors) – (NSString *)primitiveName; – (void)setPrimitiveName:(NSString *)newName; @end @implementation Department @dynamic name; – (NSString *)name { [self … Read more

Core data, how to get NSManagedObject’s ObjectId when NSFetchRequest returns NSDictionaryResultType?

Yes you can, using the very nifty but badly-documented NSExpressionDescription class. You need to add a properly-configured NSExpressionDescription object to the array of NSPropertyDescription objects you set via setPropertiesToFetch: for your NSFetchRequest. For example: NSExpressionDescription* objectIdDesc = [[NSExpressionDescription new] autorelease]; objectIdDesc.name = @”objectID”; objectIdDesc.expression = [NSExpression expressionForEvaluatedObject]; objectIdDesc.expressionResultType = NSObjectIDAttributeType; myFetchRequest.propertiesToFetch = [NSArray arrayWithObjects:objectIdDesc, anotherPropertyDesc, … Read more

How to use the first character as a section name

You should just pass “name” as the sectionNameKeyPath. See this answer to the question “Core Data backed UITableView with indexing”. UPDATE That solution only works if you only care about having the fast index title scroller. In that case, you would NOT display the section headers. See below for sample code. Otherwise, I agree with … Read more

SwiftUI View and @FetchRequest predicate with variable that can change

had the same problem, and a comment of Brad Dillon showed the solution: var predicate:String var wordsRequest : FetchRequest<Word> var words : FetchedResults<Word>{wordsRequest.wrappedValue} init(predicate:String){ self.predicate = predicate self.wordsRequest = FetchRequest(entity: Word.entity(), sortDescriptors: [], predicate: NSPredicate(format: “%K == %@”, #keyPath(Word.character),predicate)) } in this example, you can modify the predicate in the initializer.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)