swift - Differences between filtering Realm with NSPredicate and block -


i'm wondering realm's query performance. given code:

let result1 = realm.objects(person.self).filter("age < 30 , ... , ...") let result2 = realm.objects(person.self).filter({ $0.age < 30 }).filter({$0.name .... }).filter({$0.nickname ...}) 

result1 created filtering person objects using nspredicate, while result2 filtering using filter method swift's collection types.

is there performance difference between these 2 approaches filtering?

yes, there performance difference between 2 approaches.

the nspredicate-based filtering performed realm's query engine, filters directly on data in realm file without ever creating instances of person. can take advantage of knowledge of database structure perform queries more efficiently (by using indexes, instance). in contrast, block based filtering must create instances of person each object in realm in order pass them block.

there other semantic differences well, stem differing result types of 2 methods. nspredicate-based filtering returns results<t> rather [t] block-based filtering returns.

results<t> live-updating view onto results of query. can hand 1 view controller , contents update after other parts of application perform writes cause new objects begin matching predicate. can register change notifications learn when new objects begin matching predicate, existing object stops matching it, or when object matches modified in way.


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -