CoreStore.fetchOne.where not working with Date #250

Open
opened 2025-12-29 15:27:37 +01:00 by adam · 3 comments
Owner

Originally created by @Piranit on GitHub (Jan 4, 2019).

Point model have field
@NSManaged public var captured: Date
when I try
let points: [Point] = CoreStore.fetchAll(From<Point>()) // get all points
points array have many points fetched from database
let point = CoreStore.fetchOne(From<Point>().where(\.captured == points[0].captured))
I receive nil
but why?
how correctly get record by date?
pls, help me

Originally created by @Piranit on GitHub (Jan 4, 2019). Point model have field **_@NSManaged public var captured: Date_** when I try `let points: [Point] = CoreStore.fetchAll(From<Point>()) // get all points` points array have many points fetched from database `let point = CoreStore.fetchOne(From<Point>().where(\.captured == points[0].captured))` I receive nil but why? how correctly get record by date? pls, help me
Author
Owner

@JohnEstropia commented on GitHub (Jan 8, 2019):

How are you saving your Point instances?

@JohnEstropia commented on GitHub (Jan 8, 2019): How are you saving your `Point` instances?
Author
Owner

@Piranit commented on GitHub (Jan 8, 2019):

@JohnEstropia

    CoreDataService.getDataStack({ (dataStack: DataStack?) -> Void in
      if let _ = dataStack{
        try? CoreStore.perform(synchronous: { (transaction) in
          let p: Point = transaction.create(Into<Point>())
          p.captured = captured
          p.lat = lat
          p.lng = lng
          p.rideId = rideId
          p.sended = sended
        }, waitForAllObservers: true)
      }
    })
  }
@Piranit commented on GitHub (Jan 8, 2019): @JohnEstropia ```public static func savePoint(captured: Date, lat: Double, lng: Double, rideId: Int32, sended: Bool){ CoreDataService.getDataStack({ (dataStack: DataStack?) -> Void in if let _ = dataStack{ try? CoreStore.perform(synchronous: { (transaction) in let p: Point = transaction.create(Into<Point>()) p.captured = captured p.lat = lat p.lng = lng p.rideId = rideId p.sended = sended }, waitForAllObservers: true) } }) }
Author
Owner

@JohnEstropia commented on GitHub (Jan 15, 2019):

Are you sure CoreStore.fetchOne(_:) is being called after CoreStore.perform(synchronous:)?
Have you tried to use CoreStore.fetchAll(_:) instead to see if the Point is in the database at all?

@JohnEstropia commented on GitHub (Jan 15, 2019): Are you sure `CoreStore.fetchOne(_:)` is being called _after_ `CoreStore.perform(synchronous:)`? Have you tried to use `CoreStore.fetchAll(_:)` instead to see if the `Point` is in the database at all?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/CoreStore#250