jjzjj

fetchRandom

全部标签

ios - 从核心数据中获取随机对象

我需要从核心数据文件中获取随机对象,比如10个随机对象。我该怎么做?这是我的NSFetchRequest设置-(NSFetchRequest*)fetchRandom{if(!_fetchRandom){_fetchRandom=[[NSFetchRequestalloc]init];}[_fetchRandomsetEntity:[NSEntityDescriptionentityForName:@"Contacts"inManagedObjectContext:self.oneManagedObjectContext]];NSPredicate*predicate=[NSPredi