1
//Ingredient.h
@interface Ingredient : RLMObject
@property (nonatomic, copy, readwrite) NSString *name;
@end
RLM_ARRAY_TYPE(Ingredient)
//Recipe.h
@interface Recipe : RLMObject
@property (nonatomic, strong, readwrite) RLMArray<Ingredients *>< Ingredients> *ingredients;
@end
を持っているが、それは、複数の成分を追加することが正しいですか?
Ingredient *tomato = [[Ingredient alloc] init];
tomato.name = @"tomato";
Ingredient *onion = [[Ingredient alloc] init];
onion = @"onion";
Recipe *recipe = [[Recipe alloc] init];
[realm beginWriteTransaction]
[recipe.ingredients add:tomato];
[recipe.ingredients add:onion];
[realm.commitWriteTransaction];
その他の方法はありますか?
ありがとう!そして、私は 'トマト'が自動的に 'レルム'に追加されると思いますか? – Colas
オブジェクトが既に 'RLMRealm'に属していない場合、' addObject'を呼び出すと追加されます。 – TiM