Reputation: 51
We are trying to integrate Realm into our ios app in an iterative manner. Currently we have a lot of variables of the type NSArray which will ultimately have to be replaced by RLMResults. But for now I was wondering if the data from Realm db could be loaded into those variables. Here is an example of one such function :
func preloadData() {
if( realmEnabled )
{
if( self.currentLeftSideBarState == GLOBAL_CUSTOMER_STATE ) {
self.allRelations = Relationship.allObjectsInRealm(relationshipRealm)
} else if( self.currentLeftSideBarState == SINGLE_CUSTOMER_STATE ) {
let rel = Relationship( customers: currentCustomerSelected! )
if rel.realm != nil {
if let rooms = rel.linkingObjectsOfClass( RoomObj.className(), forProperty: "relationship" ) {
self.allRoomsforRelationship = rooms
}
}
}
}
}
Here, allRelations
is an RLMResults
object while allRoomsForRelationship
is an NSArray
. This leads to several inconsistencies.
It would be convenient to typecast RLMResults
to NSArray
Upvotes: 2
Views: 1181
Reputation: 4120
Since RLMResults
doesn't inherit from NSArray
, casting to an NSArray
is dangerous -- you'd lose all type safety. What you may want to look into is whether changing those declarations to id<NSFastEnumerable>
makes sense for your application, or else maybe declaring a protocol which has the methods common to both NSArray
and RLMResults
.
Upvotes: 2