Originally created by @iarata on GitHub (Sep 10, 2022).
In my app, I have the following CoreStoreObject class which I use to store assignments:
class AssignmentCore: CoreStoreObject {
@Field.Stored("id", dynamicInitialValue: { UUID() })
var id: UUID
@Field.Stored("isHidden", dynamicInitialValue: { false })
var isHidden: Bool
@Field.Coded("assignment", coder: FieldCoders.Json.self)
var assignment: Assignment?
}
I can successfully create AssignmnetCore objects and store them using the following method:
func build(assignment: Assignment, completion handler: @escaping (Result<Void, Error>) -> Void) {
self.dataStack.perform(
asynchronous: { (transaction) in
let assignmentRecord = transaction.create(Into<AssignmentCore>())
assignmentRecord.id = assignment.id
assignmentRecord.assignment = assignment
assignmentRecord.isHidden = false
},
completion: { (result) in
switch result {
case .success:
handler(.success(()))
case .failure(let error):
handler(.failure(error))
}
}
)
}
But every time that I try to use the Where clause to get a specific object using fetchAll or fetchOne it returns nil or empty. Also, the deleteAll is not deleting the object and I'm using the Where just like below.
This has been happening recently and it was working fine even before I change to develop branch.
I tried the following ways but all resulted in empty data (the data exists because if I just use fetchAll I get all the objects):
In addition, every time I try to use the == operator in the where clause I get Operator function '==' requires that 'AssignmentCore' inherit from 'NSManagedObject' error.
The example below results in the above error:
let datas = try self.dataStack.fetchAll(From<AssignmentCore>()
.where(\.id == asign.id)
)
Running on iOS 15.0
Using CoreStore develop branch
Xcode 14.0 (14A309)
Originally created by @iarata on GitHub (Sep 10, 2022).
In my app, I have the following `CoreStoreObject` class which I use to store assignments:
```
class AssignmentCore: CoreStoreObject {
@Field.Stored("id", dynamicInitialValue: { UUID() })
var id: UUID
@Field.Stored("isHidden", dynamicInitialValue: { false })
var isHidden: Bool
@Field.Coded("assignment", coder: FieldCoders.Json.self)
var assignment: Assignment?
}
```
I can successfully create `AssignmnetCore` objects and store them using the following method:
```
func build(assignment: Assignment, completion handler: @escaping (Result<Void, Error>) -> Void) {
self.dataStack.perform(
asynchronous: { (transaction) in
let assignmentRecord = transaction.create(Into<AssignmentCore>())
assignmentRecord.id = assignment.id
assignmentRecord.assignment = assignment
assignmentRecord.isHidden = false
},
completion: { (result) in
switch result {
case .success:
handler(.success(()))
case .failure(let error):
handler(.failure(error))
}
}
)
}
```
But every time that I try to use the `Where` clause to get a specific object using `fetchAll` or `fetchOne` it returns nil or empty. Also, the `deleteAll` is not deleting the object and I'm using the `Where` just like below.
This has been happening recently and it was working fine even before I change to develop branch.
I tried the following ways but all resulted in empty data (the data exists because if I just use `fetchAll` I get all the objects):
```
func isAssignmentExists(assignment asign: Assignment) -> Bool {
do {
let datas = try self.dataStack.fetchAll(From<AssignmentCore>()
// .where(format: "assignment == %@", asign)
.where(format: "id == %@", asign.id)
)
if datas.isEmpty {
return false
} else {
return true
}
} catch {
print(error.localizedDescription)
return false
}
}
```
In addition, every time I try to use the `==` operator in the where clause I get `Operator function '==' requires that 'AssignmentCore' inherit from 'NSManagedObject'` error.
The example below results in the above error:
```
let datas = try self.dataStack.fetchAll(From<AssignmentCore>()
.where(\.id == asign.id)
)
```
Running on iOS 15.0
Using CoreStore develop branch
Xcode 14.0 (14A309)
adam
added the question label 2025-12-29 15:30:52 +01:00
Since you are using the @Field property wrappers, use this syntax when querying:
.where(\.$id==asign.id)
@JohnEstropia commented on GitHub (Sep 10, 2022):
Since you are using the `@Field` property wrappers, use this syntax when querying:
```swift
.where(\.$id == asign.id)
```
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Originally created by @iarata on GitHub (Sep 10, 2022).
In my app, I have the following
CoreStoreObjectclass which I use to store assignments:I can successfully create
AssignmnetCoreobjects and store them using the following method:But every time that I try to use the
Whereclause to get a specific object usingfetchAllorfetchOneit returns nil or empty. Also, thedeleteAllis not deleting the object and I'm using theWherejust like below.This has been happening recently and it was working fine even before I change to develop branch.
I tried the following ways but all resulted in empty data (the data exists because if I just use
fetchAllI get all the objects):In addition, every time I try to use the
==operator in the where clause I getOperator function '==' requires that 'AssignmentCore' inherit from 'NSManagedObject'error.The example below results in the above error:
Running on iOS 15.0
Using CoreStore develop branch
Xcode 14.0 (14A309)
@JohnEstropia commented on GitHub (Sep 10, 2022):
Since you are using the
@Fieldproperty wrappers, use this syntax when querying:@iarata commented on GitHub (Sep 10, 2022):
I think I missed that note in the docs.
Thank you it works now 🎉