Ios Coredata处理数据(多线程)
我需要把热点放在地图上。所有这些都与CoreData一起保存(大约25000)。 所以我需要25000条注释。我还为热点实体实现了MKAnnotation协议 针对这种情况选择的解决方案是多线程。但是在地图上有了PIN之后,有些PIN没有数据(数据) 下面是填充数组中数据的代码Ios Coredata处理数据(多线程),ios,multithreading,core-data,mapkit,Ios,Multithreading,Core Data,Mapkit,我需要把热点放在地图上。所有这些都与CoreData一起保存(大约25000)。 所以我需要25000条注释。我还为热点实体实现了MKAnnotation协议 针对这种情况选择的解决方案是多线程。但是在地图上有了PIN之后,有些PIN没有数据(数据) 下面是填充数组中数据的代码 - (void)addAnnotationsForCurrentLocation { NSInteger hotSpotsCount = [HotSpot MR_countOfEntities]; sel
- (void)addAnnotationsForCurrentLocation {
NSInteger hotSpotsCount = [HotSpot MR_countOfEntities];
self.testSpotsArray = [[NSMutableArray alloc] initWithCapacity:hotSpotsCount];
NSInteger lastThread;
NSInteger threads = 5;
//calculate how much spots will be in the
NSInteger spotsInThread = hotSpotsCount/threads;
//calclulate how mush threads will be in one spot
lastThread = hotSpotsCount - spotsInThread*(threads-1);
dispatch_queue_t firstThreadQueue = dispatch_queue_create("com.thecloud.firstThreadQueue", DISPATCH_QUEUE_CONCURRENT);
dispatch_queue_t secondThreadQueue = dispatch_queue_create("com.thecloud.secondThreadQueue", DISPATCH_QUEUE_CONCURRENT);
dispatch_queue_t thirdThreadQueue = dispatch_queue_create("com.thecloud.thirdThreadQueue", DISPATCH_QUEUE_CONCURRENT);
dispatch_queue_t forthThreadQueue = dispatch_queue_create("com.thecloud.forthThreadQueue", DISPATCH_QUEUE_CONCURRENT);
dispatch_queue_t fifthThreadQueue = dispatch_queue_create("com.thecloud.fifthThreadQueue", DISPATCH_QUEUE_CONCURRENT);
dispatch_group_t fillArrayGroup = dispatch_group_create();
NSLock *arrayLock = [[NSLock alloc] init];
dispatch_group_async(fillArrayGroup, firstThreadQueue, ^{
[self fetchWithOffest:0 andLimit:spotsInThread andLock:arrayLock];
DDLogInfo(@"com.thecloud.firstThreadQueue and self.testSpotsArray objects - %i", [self.testSpotsArray count]);
});
//Other Queue
dispatch_group_notify(fillArrayGroup, dispatch_get_main_queue(), ^{
[self.treeController setAnnotations:self.testSpotsArray];
});
dispatch_release(fillArrayGroup);
}
- (void)fetchWithOffest:(NSInteger)offset andLimit:(NSInteger)limit andLock:(NSLock *)arrayLock {
NSFetchRequest *request = [HotSpot MR_requestAll];
[request setFetchOffset:offset];
[request setFetchLimit:limit];
[request setReturnsObjectsAsFaults:NO];
NSArray *array = [HotSpot MR_executeFetchRequest:request];
for (int i=0; i < [array count]; i++) {
HotSpot *spot = (HotSpot *)[array objectAtIndex:i];
[spot convertLogitudeAndLattitudeToLocationCoordinate];
[arrayLock lock];
[self.testSpotsArray addObject:spot];
[arrayLock unlock];
}
}
我使用直接赋值
- (void)prepareAnnotation {
_title = self.name;
_subtitle = self.spotToAddress.addressLine1;
_coordinate = CLLocationCoordinate2DMake([self.latitude doubleValue], [self.longitude doubleValue]);
}
问题解决了。我确实改变了我的实体模型。现在,当我将实体添加到annotations数组而不是
-(NSString *)title {
return self.title;
}
-(NSString *)subtitle {
return self.spotToAddress.addressLine1;
}
-(CLLocationCoordinate2D) coordinate {
return CLLocationCoordinate2DMake([self.latitude doubleValue], [self.longitude doubleValue]);
}
-(NSString *)title {
return self.title;
}
-(NSString *)subtitle {
return self.spotToAddress.addressLine1;
}
-(CLLocationCoordinate2D) coordinate {
return CLLocationCoordinate2DMake([self.latitude doubleValue], [self.longitude doubleValue]);
}
我使用直接赋值
- (void)prepareAnnotation {
_title = self.name;
_subtitle = self.spotToAddress.addressLine1;
_coordinate = CLLocationCoordinate2DMake([self.latitude doubleValue], [self.longitude doubleValue]);
}
看起来你的问题是标题方法
-(NSString*)title{return self.title;}
将导致无限循环,因为self.title
调用从中调用它的方法。