您好我已創建使用從核心數據的數組:如何從這個數組中創建一個自定義字符串?
NSArray* invoiceItem =[fetchedResultsController fetchedObjects];
其返回以下根據日誌:
"<Invoice: 0x8545900> (entity: Invoice; id: 0x8542dd0 <x-coredata://AF2BBB5C-4135-45EB-A421-5036AE02D2A0/Invoice/p19> ;
data: {\n GSTAmount = \"0.75\";\n amountPaid = nil;\n cardID = 0;\n
customer = \"\";\n date = \"23/12/2011\";\n incTaxPrice = \"8.25\";\n
incTaxTotal = \"8.25\";\n invoiceNumber = a20;\n itemCode = 1035;\n
paymentMethod = nil;\n price = \"7.50\";\n quantity = 1;\n saleStatus = I;\n
taxCode = GST;\n timeStamp = \"2011-12-22 22:10:25 +0000\";\n total = \"7.5\";\n})",
"<Invoice: 0x8545c00> (entity: Invoice; id: 0x8543390 <x-coredata://AF2BBB5C-4135-45EB-A421-5036AE02D2A0/Invoice/p20> ;
data: {\n GSTAmount = \"0.55\";\n amountPaid = nil;\n cardID = 0;\n
customer = \"\";\n date = \"23/12/2011\";\n incTaxPrice = \"6.05\";\n
incTaxTotal = \"12.1\";\n invoiceNumber = a20;\n itemCode = 1040;\n
paymentMethod = nil;\n price = \"5.50\";\n quantity = 2;\n saleStatus = I;\n
taxCode = GST;\n timeStamp = \"2011-12-22 22:11:14 +0000\";\n total = 11;\n})"
)
我的總體目標是簡單地創建itemCode特性的串格式化,以便它可以成爲pdf中的一列,因爲除了創建tableview的圖像並將其插入到PDF中之外,我不知道任何其他方式創建表格。我想避免這樣做。
所以不是我想從上面的陣列得到一個字符串,格式如下
"1035\n1040"
我不知道如何通過自身獲得來自陣列的項目代碼屬性。請注意,商品代碼的長度不同,並不總是數字。
任何幫助將不勝感激!如果任何人有任何其他提示或更好的方式來實現我想做的事,我所有的耳朵:)
編輯
純粹爲了解決方案的廣度。在我離開電腦幾分鐘後,我偶然想出了一個解決方案。我不會用我的解決方案,因爲另一個似乎更有效率/更重要。不過,我想我會讓別人看到另一種方法。
NSMutableArray *itemCodes =[invoiceItem mutableArrayValueForKey:@"itemCode"];
NSString *holdingString =[NSString stringWithFormat:@"%@",itemCodes];
NSString *itemColumn = [holdingString stringByReplacingOccurrencesOfString:@"," withString:@"\n"];