1

Hi guys so basically this is a project I've been working on and I'm stuck at using coreData while assigning bitwise left shift values to an attribute. Additionally after assigning I would also need to identify them.

Here is an example scenario on what I am trying to do.

Basically let say I have an Entity called Venues with attributes venueName and venueSports. Then I have another Entity called Sports with attribute sportsType and sportsNumber.

So basically: venueName: the venues name - taken from a textboxfield (already have this working) sportsType: the name of the sport - taken from a textboxfield (already have this working)

sportsNumber: so this is where I need a method to store a number and each time I add to the list it uses the bitwise left shift to store the sportNumber.

venueSports: So basically the Sports Entity will generate a tableView which I can select the sports and save it to this venue (already have this) - so now I need to add multiple sports to this attribute which only accepts 1 integer and after I need to identify which bit. So basically if I got 9 I would be getting from 1 8 bit and if I get 14 it would be 2 4 8 bit. How do I do this?

- (NSManagedObjectContext *) managedObjectContext {
    NSManagedObjectContext *context = nil;

    id delegate = [[UIApplication sharedApplication] delegate];

    if ([delegate performSelector:@selector(managedObjectContext)]) {
        context = [delegate managedObjectContext];
    }

    return context;
}

- (IBAction)save:(id)sender {
    NSManagedObjectContext *context = [self managedObjectContext];

    NSManagedObject *newSport = [NSEntityDescription  insertNewObjectForEntityForName:@"Sports" inManagedObjectContext:context];


    [newSport setValue:textboxSport.text forKey:@"sportType"];

This is what I have so far which works fine but need the above to features.

Thanks in advance guys I'm new to Objective C so any help is really appreciated.

TEZZ
  • 179
  • 1
  • 15
  • 1
    Check out this answer http://stackoverflow.com/questions/4716734/how-to-use-binary-flags-in-core-data – Dominic Jun 02 '16 at 14:11
  • Sounds like you should build a many-many relationship between Venue and Sports, and populate this relationship based on the Sports applicable to a given Venue. Being many-many, you can assign several Sports to a Venue without needing to use bitwise left shifts to combine them into a single value. – pbasdf Jun 02 '16 at 21:22
  • Any links that have an example of this for the many to many relationship in core data? – TEZZ Jun 04 '16 at 05:21

0 Answers0