ios - Return unique/distinct values with Realm query -
i have message/rlmobject
model has nsstring *jabberid
property/row , want retrieve every unique
value inside row.
in other word, want retrieve non-repeated jabberid
values message
model. can out figuring this?
the way use coredata using returnsdistinctresults
setting on nsfetchrequest
.
functional programming approach since swift has it, , realm lazy loads; not easy/available solution in objective-c swift @ least: swift
let distincttypes = reduce(realm().objects(user), []) { $0 + (!contains($0, $1.type) ? [$1.type] : [] ) }
updated:
swift reduce kind of performance intensive, allocating bunch of intermediate array's, instead following should better performance wise, must explicitly cast
let distincttypes = array(set(realm().objects(user).valueforkey("type") as! [string]))
Comments
Post a Comment