0
我需要在Core Data
屬性中存儲uint64_t
號碼。我也需要在謂詞中使用這個屬性。
問題是,核心數據只有Integer64類型,並且我無法對該屬性執行提取請求。
例如:核心數據無符號long long best practices
NSNumber *pid = @(9224992848802061623ULL); // some unsigned long long
// create a person with this id
Person *person = [NSEntityDescription insertNewObjectForEntityForName:@"Person" inManagedObjectContext:self.context];
person.personId = pid; // personId is core data NSNumber property typed integer 64
[self.context save:nil];
// now try to fetch this person we just added
NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"Person"];
request.predicate = [NSPredicate predicateWithFormat:@"personId == %@", pid];
NSArray *match = [self.context executeFetchRequest:request error:nil];
// NO RESULTS!
正如你可以看到這裏,我試圖獲取相同的PERSONID正如我剛纔創建的時候沒有結果。
我假設問題在於Core Data將其存儲爲有符號值,因此值不同,但我該如何解決這個問題?
那麼排序呢?假設我想要一個也由personId排序的提取請求?現在發生的事情是,大數變成負數(因爲它們被視爲簽名),所以他們排序到列表的開頭。
那麼在處理unsigned long long和Core Data時最佳做法是什麼?
你可以解釋什麼時使用小數?它似乎工作,但我不明白爲什麼 – Eyal 2014-09-23 14:35:47
@Eyal它將該值存儲爲一個NSDecimalNumber,其實質上是基數爲10的數字與38位數的精度。所以,爲64位無符號整型空間提供足夠的空間。 – 2014-09-23 14:52:59