CoreStore icon indicating copy to clipboard operation
CoreStore copied to clipboard

CoreStore.fetchOne.where not working with Date

Open Piranit opened this issue 6 years ago • 3 comments

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

Piranit avatar Jan 04 '19 16:01 Piranit

How are you saving your Point instances?

JohnEstropia avatar Jan 08 '19 01:01 JohnEstropia

@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 avatar Jan 08 '19 09:01 Piranit

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 avatar Jan 15 '19 09:01 JohnEstropia