-1
我有30個房間,每個房間應該有5個同樣的RoomAttributes。我該如何做NSSet更容易保存在CoreData中?
我有Room和RoomAttributes之間的多對多關係。
我的解決方案是創建30 * 5 = 150 RoomAttributes併爲每個房間創建RoomAttribute的NSSet。這是很多工作。
我如何創造一個房間:
Raum *raum = [NSEntityDescription insertNewObjectForEntityForName:@"Raum" inManagedObjectContext:context];
raum.raumName = @"Main";
raum.etage = @"2. Stock, Raum 1.203";
raum.beschreibung = @"Gut beleuchtet";
raum.raumpreis = [NSNumber numberWithDouble:210];
raum.raumname = @"Besprechungsraum";
如何創建RoomAttributes:
Raumattribute *attribute =[NSEntityDescription insertNewObjectForEntityForName:@"Raumattribute" inManagedObjectContext:context];
attribute.attributname = @"Beamer";
attribute.schalter = [NSNumber numberWithBool:NO];
Raumattribute *attribute2 =[NSEntityDescription insertNewObjectForEntityForName:@"Raumattribute" inManagedObjectContext:context];
attribute2.attributname = @"Behindertengerecht";
attribute2.schalter = [NSNumber numberWithBool:NO];
如何我創建的NSSet:
NSSet *attributeFurRaum = [NSSet setWithObjects:attribute1, attribute2,nil];
raum.raumattribute = attributeFurRaum;
我怎樣才能使這更容易?
我編輯了我的問題 – Bashud
我更新了我的答案 –
我添加了我的評論 – Manav