1

我正在尝试使用实体上的获取请求发送多个 localNofications 虽然这段代码工作正常

   NSFetchRequest *myRequest = [[NSFetchRequest alloc] init];
   NSPredicate *predicate = [NSPredicate predicateWithFormat:@"active == YES"];
  [myRequest setEntity:[NSEntityDescription entityForName:@"Entry" inManagedObjectContext:managedObjectContext]];
  [myRequest setPredicate:predicate];
  NSError *error = nil;
  NSArray *fetchedObjects = [self.managedObjectContext executeFetchRequest: myRequest error: &error];
  if (fetchedObjects == nil){
 // Deal with error...
 }

// We fill the NSMutableArray with the values of the fetch
self.activeList = [[NSMutableArray alloc] initWithArray:[fetchedObjects valueForKey:@"textbody"]];
[self scheduleAlarms:[self.activeList objectAtIndex:0]];
[fetchedObjects release]; //this line crashes the app

1) 如果我释放 fetchedObjects,应用程序就会崩溃。我不应该释放它吗?

2) 我可以使用 localNotif.userinfo 来优化代码,而不是调用一个方法来使用我的 activeList 中的字符串来安排每个 localNotification 吗?我不知道该怎么做。

谢谢,

麦克风

4

1 回答 1

0

1)executeFetchRequest返回一个自动释放的NSArray,你不需要手动释放它

2)不清楚你要优化什么......

于 2011-01-12T22:24:01.703 回答