将对象添加到RLMArray?

时间:2016-12-13 18:26:20

标签: objective-c nsmutablearray realm

我有课程

n

添加多种成分是否正确?

CREATE TABLE Operations(

   operation_id       int not null AUTO_INCREMENT,
   PRIMARY KEY(operation_id),
   openingtime        time,
   closingTime        time,
   operationDay       ?????
   restaurant_id      int,
   FOREIGN KEY(restaurant_id)
   REFERENCES restaurant(restaurant_id)
   ON UPDATE CASCADE
);

example

id  = 1
openingtime = 7:00am
closingTime = 10:00pm
operationDay = monday
restaurant_id = 2

还有其他办法吗?

1 个答案:

答案 0 :(得分:1)

关闭! RLMArray遵循NSMutableArray的方法命名约定。

所以正确的方法名称是

[realm beginWriteTransaction]
[recipe.ingredients addObject:tomato];
[recipe.ingredients addObject:onion];
[realm.commitWriteTransaction];

查看RLMArray's documentation以获取可以使用的完整方法列表。例如,更简化的添加对象的方法可以是:

[realm beginWriteTransaction]
[recipe.ingredients addObjects:@[tomato, onion]];
[realm.commitWriteTransaction];