Skip to content

Commit

Permalink
Xcode 15 support: Removing Predicate typealias to NSPredicate
Browse files Browse the repository at this point in the history
  • Loading branch information
spnkr committed Aug 2, 2023
1 parent 3c1b0b6 commit 1623584
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ public protocol ManagedObjectDeletable {
/// Removes all objects from the foreground or background context
static func destroyAll(using: ContextMode)
/// Removes all objects matching the predicate from the context
static func destroyAll(matching: Predicate?, context: NSManagedObjectContext)
static func destroyAll(matching: NSPredicate?, context: NSManagedObjectContext)
/// Removes all objects matching the predicate from the foreground or background context
static func destroyAll(matching: Predicate?, using: ContextMode)
static func destroyAll(matching: NSPredicate?, using: ContextMode)
}

public extension ManagedObjectDeletable {
Expand All @@ -19,10 +19,10 @@ public extension ManagedObjectDeletable {
static func destroyAll(using: ContextMode = .foreground) {
destroyAll(context: contextModeToNSManagedObjectContext(using))
}
static func destroyAll(matching: Predicate? = nil, using: ContextMode = .foreground) {
static func destroyAll(matching: NSPredicate? = nil, using: ContextMode = .foreground) {
destroyAll(matching: matching, context: contextModeToNSManagedObjectContext(using))
}
static func destroyAll(matching: Predicate? = nil, context: NSManagedObjectContext) {
static func destroyAll(matching: NSPredicate? = nil, context: NSManagedObjectContext) {
let request = (self as! NSManagedObject.Type).fetchRequest()
request.entity = (self as! NSManagedObject.Type).entity()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public extension ManagedObjectFind {
static func find(column: String, value: Any, context: NSManagedObjectContext) -> Self? {

let request = NSFetchRequest<Self>()
request.predicate = Predicate("\(column) = %@", value)
request.predicate = NSPredicate("\(column) = %@", value)
request.fetchLimit = 1
request.entity = entity()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public extension ManagedObjectFindOrCreateBy {
/// Same as `findOrCreate(column: String, value: Any, using: ContextMode = .foreground)`, but allows you to pass your own `NSManagedObjectContext`.
static func findOrCreate(column: String, value: Any, context: NSManagedObjectContext) -> Self {
let request = NSFetchRequest<Self>()
request.predicate = Predicate("\(column) = %@", value)
request.predicate = NSPredicate("\(column) = %@", value)
request.entity = entity()

do {
Expand Down
4 changes: 1 addition & 3 deletions Sources/ActiveCoreData/Other Extensions/Predicate.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import Foundation
import CoreData

public typealias Predicate = NSPredicate

public extension NSPredicate {
/// Create an NSPredicate.
///
Expand All @@ -22,6 +20,6 @@ public extension NSPredicate {
/// A predicate that matches every object.
/// Easier than having to write conditions for 'if the predicate is nil'.
static func empty() -> NSPredicate {
Predicate("1 = 1")
NSPredicate("1 = 1")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ final class ContextSynchronizationTests: BaseTestCase {
japan.addToLanguages(jp1)
mexico.addToLanguages(es)

let withSpanishLanguage = Predicate("languages contains %@", es)
let withSpanishLanguage = NSPredicate("languages contains %@", es)
XCTAssertEqual(Country.countFor(withSpanishLanguage), 2)
XCTAssertEqual(Country.countFor(withSpanishLanguage, using: .background), 0)
XCTAssertEqual(Country.countFor(withSpanishLanguage, using: .foreground), 2)
Expand Down
10 changes: 5 additions & 5 deletions Tests/ActiveCoreDataTests/CoreTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ final class CoreTests: BaseTestCase {
japan.addToLanguages(jp1)
mexico.addToLanguages(es)

let withSpanishLanguage = Predicate("languages contains %@", es)
let withSpanishLanguage = NSPredicate("languages contains %@", es)
XCTAssertEqual(Country.countFor(withSpanishLanguage), 2)

Country.destroyAll(matching: withSpanishLanguage)
Expand Down Expand Up @@ -231,17 +231,17 @@ final class CoreTests: BaseTestCase {
let book2 = Book.findOrCreate(id: "2")
book2.title = "Book 2"

let results = Book.searchFor(Predicate("title contains %@", "Book"), context: c)
let results = Book.searchFor(NSPredicate("title contains %@", "Book"), context: c)
XCTAssertEqual(results.count, 2)

let results2 = Book.searchFor(Predicate("title contains %@", "Book"), limit: 1, using: .foreground)
let results2 = Book.searchFor(NSPredicate("title contains %@", "Book"), limit: 1, using: .foreground)
XCTAssertEqual(results2.count, 1)

let results3 = Book.searchFor(Predicate("title contains %@", "Book"), sortBy: [SortDescriptor("title")], using: .foreground)
let results3 = Book.searchFor(NSPredicate("title contains %@", "Book"), sortBy: [SortDescriptor("title")], using: .foreground)
XCTAssertEqual(results3.count, 2)
XCTAssertEqual(results3.first!.title, "Book 1")

let results4 = Book.searchFor(Predicate("title contains %@", "Book"), sortBy: [NSSortDescriptor(key: "title", ascending: false)], using: .foreground)
let results4 = Book.searchFor(NSPredicate("title contains %@", "Book"), sortBy: [NSSortDescriptor(key: "title", ascending: false)], using: .foreground)
XCTAssertEqual(results4.count, 2)
XCTAssertEqual(results4.first!.title, "Book 2")

Expand Down

0 comments on commit 1623584

Please sign in to comment.