core data - How do I check if an NSSet contains an object of a kind of class? -


how implement following instance method nsset:

- (bool)containsmemberofclass:(class)aclass 

here's why want know:

core data model: enter image description here

how add facebook authorization user's authorizations nsset, if 1 doesn't exist. in other words, user can have many authorizations (in case choose add twitter (e.g.) authorization in future) should have 1 of each kind of authorization. so, if (![myuser.authorizations containsmemberofclass:[facebook class]]), add facebook authorization instance myuser.

unfortunately, have loop through of authorizations , check:

@interface nsset (containsadditions)  - (bool)containskindofclass:(class)class; - (bool)containsmemberofclass:(class)class;  @end  @implementation nsset (containsadditions)  - (bool)containskindofclass:(class)class {     (id element in self) {         if ([element iskindofclass:class])             return yes;     }     return no; }  - (bool)containsmemberofclass:(class)class {     (id element in self) {         if ([element ismemberofclass:class])             return yes;     }     return no; }  @end 

Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -