所以,有一個很難解引用一些數據我已經裝入數組和字典:訪問字典的陣列在Objective-C
內的控制器:
- (void)setupVendorsArray {
self.vendorsArray = [NSArray arrayWithObjects:@"Toyota", @"Honda",nil];
}
- (void)setupProductFamiliesHash {
NSArray *lowcost = [NSArray arrayWithObjects:@"Corolla", @"Fit",nil];
NSArray *midrange = [NSArray arrayWithObjects:@"Camry", @"Accord",nil];
NSArray *highend = [NSArray arrayWithObjects:@"Lexus", @"Acura",nil];
NSArray *trucks = [NSArray arrayWithObjects:@"Tacoma", @"Ridgeline",nil];
NSDictionary *lc = [NSDictionary dictionaryWithObjects:lowcost forKeys:self.vendorsArray];
NSDictionary *mr = [NSDictionary dictionaryWithObjects:midrange forKeys:self.vendorsArray];
NSDictionary *he = [NSDictionary dictionaryWithObjects:highend forKeys:self.vendorsArray];
NSDictionary *tk = [NSDictionary dictionaryWithObjects:trucks forKeys:self.vendorsArray];
self.productFamiliesHash = [NSArray arrayWithObjects:lc,mr,he,tk,nil];
}
在gdb中打印對象結果在本作productFamiliesHash:
(gdb) print-object self.productFamiliesHash
<__NSArrayI 0x6b2c760>(
{
Toyota = "Corolla";
Honda = "Fit";
},
{
Toyota = "Camry";
Honda = "Accord";
},
{
Toyota = "Lexus";
Honda = "Acura";
},
{
Toyota = "Tacoma";
Honda = "Ridgeline";
}
)
但是,對我的生活中,我似乎無法訪問,例如,豐田花冠,我期望我能在gdb這樣做:
(gdb) p [[productFamiliesHash objectAtIndex:0] objectForKey:@"Toyota"]
然而,GDB給出:
Unable to call function "objc_msgSend" at 0x156408c: no return type information available.
如何提領我在陣列內的字典?
你是不是正確的。在gdb控制檯中嘗試'po'而不是'p'。 'po'打印出ObjC對象。 –
當對象確實是一個數組時,您應該避免使用名稱'productFamiliesHash'。 – ThomasW