Skip to content

Commit 1623584

Browse files
committed
Xcode 15 support: Removing Predicate typealias to NSPredicate
1 parent 3c1b0b6 commit 1623584

File tree

6 files changed

+13
-15
lines changed

6 files changed

+13
-15
lines changed

Sources/ActiveCoreData/ManagedObject/ManagedObjectDeletable.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ public protocol ManagedObjectDeletable {
77
/// Removes all objects from the foreground or background context
88
static func destroyAll(using: ContextMode)
99
/// Removes all objects matching the predicate from the context
10-
static func destroyAll(matching: Predicate?, context: NSManagedObjectContext)
10+
static func destroyAll(matching: NSPredicate?, context: NSManagedObjectContext)
1111
/// Removes all objects matching the predicate from the foreground or background context
12-
static func destroyAll(matching: Predicate?, using: ContextMode)
12+
static func destroyAll(matching: NSPredicate?, using: ContextMode)
1313
}
1414

1515
public extension ManagedObjectDeletable {
@@ -19,10 +19,10 @@ public extension ManagedObjectDeletable {
1919
static func destroyAll(using: ContextMode = .foreground) {
2020
destroyAll(context: contextModeToNSManagedObjectContext(using))
2121
}
22-
static func destroyAll(matching: Predicate? = nil, using: ContextMode = .foreground) {
22+
static func destroyAll(matching: NSPredicate? = nil, using: ContextMode = .foreground) {
2323
destroyAll(matching: matching, context: contextModeToNSManagedObjectContext(using))
2424
}
25-
static func destroyAll(matching: Predicate? = nil, context: NSManagedObjectContext) {
25+
static func destroyAll(matching: NSPredicate? = nil, context: NSManagedObjectContext) {
2626
let request = (self as! NSManagedObject.Type).fetchRequest()
2727
request.entity = (self as! NSManagedObject.Type).entity()
2828

Sources/ActiveCoreData/ManagedObject/ManagedObjectFind.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public extension ManagedObjectFind {
3535
static func find(column: String, value: Any, context: NSManagedObjectContext) -> Self? {
3636

3737
let request = NSFetchRequest<Self>()
38-
request.predicate = Predicate("\(column) = %@", value)
38+
request.predicate = NSPredicate("\(column) = %@", value)
3939
request.fetchLimit = 1
4040
request.entity = entity()
4141

Sources/ActiveCoreData/ManagedObject/ManagedObjectFindOrCreateBy.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public extension ManagedObjectFindOrCreateBy {
2626
/// Same as `findOrCreate(column: String, value: Any, using: ContextMode = .foreground)`, but allows you to pass your own `NSManagedObjectContext`.
2727
static func findOrCreate(column: String, value: Any, context: NSManagedObjectContext) -> Self {
2828
let request = NSFetchRequest<Self>()
29-
request.predicate = Predicate("\(column) = %@", value)
29+
request.predicate = NSPredicate("\(column) = %@", value)
3030
request.entity = entity()
3131

3232
do {

Sources/ActiveCoreData/Other Extensions/Predicate.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import Foundation
22
import CoreData
33

4-
public typealias Predicate = NSPredicate
5-
64
public extension NSPredicate {
75
/// Create an NSPredicate.
86
///
@@ -22,6 +20,6 @@ public extension NSPredicate {
2220
/// A predicate that matches every object.
2321
/// Easier than having to write conditions for 'if the predicate is nil'.
2422
static func empty() -> NSPredicate {
25-
Predicate("1 = 1")
23+
NSPredicate("1 = 1")
2624
}
2725
}

Tests/ActiveCoreDataTests/ContextSynchronizationTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ final class ContextSynchronizationTests: BaseTestCase {
129129
japan.addToLanguages(jp1)
130130
mexico.addToLanguages(es)
131131

132-
let withSpanishLanguage = Predicate("languages contains %@", es)
132+
let withSpanishLanguage = NSPredicate("languages contains %@", es)
133133
XCTAssertEqual(Country.countFor(withSpanishLanguage), 2)
134134
XCTAssertEqual(Country.countFor(withSpanishLanguage, using: .background), 0)
135135
XCTAssertEqual(Country.countFor(withSpanishLanguage, using: .foreground), 2)

Tests/ActiveCoreDataTests/CoreTests.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ final class CoreTests: BaseTestCase {
203203
japan.addToLanguages(jp1)
204204
mexico.addToLanguages(es)
205205

206-
let withSpanishLanguage = Predicate("languages contains %@", es)
206+
let withSpanishLanguage = NSPredicate("languages contains %@", es)
207207
XCTAssertEqual(Country.countFor(withSpanishLanguage), 2)
208208

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

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

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

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

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

0 commit comments

Comments
 (0)