Roobiq / RBQFetchedResultsController

Drop-in replacement for NSFetchedResultsController backed by Realm.
MIT License
476 stars 70 forks source link

Support transient properties for sectionNameKeyPath #101

Open michelalbers opened 8 years ago

michelalbers commented 8 years ago

I think it would be beneficial to have transient property support in the sectionNameKeyPath, e.g.:

class News : Object {
  dynamic var section : String {
    get {
      if self.didRead == true {
          return "Old news"
      } else {
          return " New news"
      }
    }
  }

  ...  
}

While this works ... kinda ... it produces a lot of crashes complaining about a non-stored property. This would solve the issue with using NSDate #58 as sectionNameKeyPath as well.

bigfish24 commented 8 years ago

What is the specific crash that is produced?

michelalbers commented 8 years ago

@bigfish24: the error produced: Terminating app due to uncaught exception 'Invalid sort property', reason: 'Cannot sort on property 'section' on object of type 'Post': property not found.'

Full crashlog:

Terminating app due to uncaught exception 'Invalid sort property', reason: 'Cannot sort on property 'section' on object of type 'Post': property not found.'

0   CoreFoundation                      0x0000000106a7ed85 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x0000000108eeadeb objc_exception_throw + 48
    2   Realm                               0x0000000105620a47 _ZL15RLMPreconditionbP8NSStringS0_z + 647
    3   Realm                               0x0000000105623b8c _ZN12_GLOBAL__N_127RLMValidatedPropertyForSortEP15RLMObjectSchemaP8NSString + 364
    4   Realm                               0x00000001056235a7 _Z27RLMSortOrderFromDescriptorsP15RLMObjectSchemaP7NSArray + 679
    5   Realm                               0x0000000105728f04 _ZZ44-[RLMResults sortedResultsUsingDescriptors:]ENK4$_12clEv + 180
    6   Realm                               0x00000001057271d6 _ZL15translateErrorsIZ44-[RLMResults sortedResultsUsingDescriptors:]E4$_12EDaOT_P8NSString + 38
    7   Realm                               0x0000000105727158 -[RLMResults sortedResultsUsingDescriptors:] + 72
    8   RBQFetchedResultsController         0x000000010547d00a -[RBQFetchRequest fetchObjects] + 442
    9   RBQFetchedResultsController         0x000000010547014b -[RBQFetchedResultsController createCacheWithRealm:cacheName:forFetchRequest:sectionNameKeyPath:] + 219
    10  RBQFetchedResultsController         0x0000000105469f4d -[RBQFetchedResultsController performFetch] + 445
    11  SwiftFetchedResultsController       0x0000000105e3c677 _TFC29SwiftFetchedResultsController24FetchedResultsController12performFetchfT_Sb + 39

Any help would be greatly appreciated. Thank you for your awesome work anyway :)

afinlayson commented 8 years ago

I'm also trying to do this. Would like to use a readonly property (transient) to sort and make sectionNameKeyPath

inPhilly commented 7 years ago

Any thoughts on this? NSFetchedResultsController does this flawlessly, and much of the code I am trying to convert relies on that. It is not really feasible to add a bunch of new fields in order to store sectionNameKeyPath information. This is kind of a big deal... I am interested to know if this is being updated.