做iOS開發已經兩年多了。最近,在整理以前的代碼,找到當時卡殼的一些代碼片段,寫部落格跟大家分享一下。歡迎iOS初學者訂閱我的部落格,有什麼問題可以留言交流。以下正文:
可能很多人不知道NSArray, NSDictionary有種很簡單的初始化方法:
NSArray *array = @[@"str0", @"str1", str"2"]; 相當于 [NSArray arrayWithObjects:<#(id), ...#>, nil]; 這個方法
NSDictionary *dictionary = @{"key0":"value0", "key1":"value1"}; 相當于 [NSDictionary dictionaryWithObjectsAndKeys:<#(id), ...#>, nil]; 這個方法
再來個複雜點的
NSDictionary *parameters = @{@"jsonfilter": @[@{@"field": @"productId", @"data": @{@"type": @"string", @"value":_channel.productId, @"comparison":@"eq"}}, @{@"field": @"channelCode", @"data": @{@"type": @"string", @"value":_channel.channelCode, @"comparison":@"eq"}}], @"limit": @"10", @"start": @"0", @"dir": @"ASC", @"sort": @"channelCode"};
這樣寫是不是感覺很簡單?