0
我想弄清楚的查詢上的plist最好的辦法。因此,試圖在做一個SQL相當於等等和soforth ...使用的plist作爲SQL表相當於 「SELECT * FROM sometable WHERE somecol = someval AND someothercol = someotherval AND」 ......。來自Ruby和MySQL,這只是一個簡單的查詢很多代碼。結果如預期般回覆(至少在第一次運行時他們做了,我沒有嚴格測試),沒有任何錯誤。SQL SELECT語句相當於查詢上的plist
因此,這裏的問題:有沒有在某個地方的文檔一些簡單的方法隱藏,這將使這個少笨重? 如果不是什麼更好的方法?
EPFramework.m
// LOAD PLIST AND FILTER MULTIPLE TIMES
-(NSMutableArray *)loadPlistAndFilterMultipleTimes:(NSString *)plist ArrayOfKeys:(NSArray *)arrayOfKeys ArrayOfKeyValues:(NSArray *)arrayOfKeyValues
{
// set the array counts
int arrayOfKeysCount = [arrayOfKeys count];
int arrayOfKeyValuesCount = [arrayOfKeyValues count];
// initialize the array to return
NSMutableArray *arrayFilteredResults = [[[NSMutableArray alloc] init] retain];
// qualify the search
if(arrayOfKeysCount == arrayOfKeyValuesCount && arrayOfKeysCount > 0 && arrayOfKeyValuesCount > 0)
{
// get the plist
NSString *fullFileName = [NSString stringWithFormat:@"%@.plist", plist];
NSString *path = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:fullFileName];
// put the plist records into an array
NSArray *arrayOfDictionaryItemsInPlist = [[NSMutableArray alloc] initWithContentsOfFile:path];
// load our dynamic array for mutability throughout the loops
NSMutableArray *arrayFiltered = [[[NSMutableArray alloc] initWithArray:arrayOfDictionaryItemsInPlist] retain];
// build an array of the final results to return
for(int i=0; i < arrayOfKeysCount; i ++)
{
// initialize this loops search criteria
NSString *key = [arrayOfKeys objectAtIndex:i];
id value = [arrayOfKeyValues objectAtIndex:i];
// set the filter
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"%K == %@", key, value];
// filter the result
arrayFilteredResults = [[[NSArray alloc] initWithArray:[arrayFiltered filteredArrayUsingPredicate:predicate]] retain];
}
} else {
NSLog(@"arrOfKeys count does not match arrayOfKeyValues count"); // the search did not qualify
}
// return the results
return arrayFilteredResults;
// release the allocated memory
[arrayFilteredResults release];
}
IndexController.m
NSArray *arrayOfKeys = [NSArray arrayWithObjects:
[NSString stringWithString:@"recordset"],
[NSString stringWithString:@"ep_object_attribute_id"],
nil];
NSArray *arrayOfKeyValues = [NSArray arrayWithObjects:
[NSString stringWithString:@"1778587279"],
[NSNumber numberWithInt:133],
nil];
NSMutableArray *arrayOfResult = [epFrameWork loadPlistAndFilterMultipleTimes:@"FormEntries" ArrayOfKeys:arrayOfKeys ArrayOfKeyValues:arrayOfKeyValues];
NSLog(@"arrayOfResult: %@", arrayOfResult);
好像你正在編寫更多的代碼,並獲得最差而不僅僅是使用CoreData或sqlite。當您使用一系列plists來模擬數據庫中的表時,爲什麼不使用數據庫或CoreData? – bryanmac
概括地說,我只有1個月讓我的項目出了門。我只做了大約一個月左右的Objective-C。一切從我研究,我已經看過了代碼示例,在我看來,對於所有其他替代的Plist學習曲線的時間內我有太陡。根據我的情況,你會推薦什麼?從您的角度來看,數據存儲的複雜程度與數據庫或核心數據方法一樣複雜嗎?也許我對整個數據存儲主題的方向是錯誤的。 – iamtoc
我真的項目是很簡單的我沒有預料到的,學習核心數據的需要,這個月至少不會。從我所有的計算結果和項目的規格來看,我剛纔確定了plists就足夠了。 – iamtoc