我有5000個地區和城市對。我想把這5000個地區劃分爲Coredata。每個地區都有一個城市,每個城市都可以有很多地區。我有2個實體,即區和城市對。我如何有效地做到這一點?如何製作對象並正確使用coredata?
for (int i=0; i<[IndonesiaDistrictToSave count]; i++) {
int index;
for (int j=0; j<[[IndonesiaDistrictToSave objectAtIndex:i] length]; j++) {
if([[IndonesiaDistrictToSave objectAtIndex:i] characterAtIndex:j]==','){
index=j;
}
}
NSString * DistrictName=[[IndonesiaDistrictToSave objectAtIndex:i] substringToIndex:index];
NSString * CityName=[[IndonesiaDistrictToSave objectAtIndex:i] substringFromIndex:index+1];
District * theDistrict = (District *)[GrabClass getObjectWithStringOfValue:DistrictName fromTable:@"District" withAttribut:@"Name"];
theDistrict.City= (City *)[GrabClass getObjectWithStringOfValue:CityName fromTable:@"City" withAttribut:@"Name"];
}
getObjectWithStringOfValue是查找該對象是否已經存在,它會返回它的方法,但如果對象不存在,這將是使一個新的,並返回
,然後我使用該代碼來保存所有印度尼西亞地區,現在有超過4500個地區,如果我使用時間間隔,每個地區我得到0.013773,但它仍然很慢,我怎麼能使它更快?
有沒有辦法獲得搜索結果的可變陣列代理?
有一個以'-get *'開頭的函數的特殊用法。我建議你使用不同的前綴。 –
Alexsander是對的:當我們在ManagedObject子類上使用-get *和-add *前綴方法時,遇到了很大的麻煩。 – vikingosegundo