在“只是为了好玩”下提交此文件,您将如何做到这一点:
currencyLabels = [[NSMutableArray alloc] initWithObjects:@"Canadian Dollars", @"Euros", @"British Pounds", @"U.S. Dollars", @"United Arab Emirates Dirhams", @"Afghanistan Afghanis", @"Albania Leke", @"Armenia Drams", @"Netherlands Antilles Guilders", @"Angola Kwanza", @"Argentina Pesos", @"Aruba Guilders/Florins", @"Azerbaijan Manats", @"Bosnia/Herzegovina Convertible Marka", @"Barbados Dollars", @"Bangladesh Taka", @"Bulgaria Leva", @"Bahrain Dinars", @"Burundi Francs", @"Bermuda Dollars", @"Brunei Darussalam Dollars", @"Bolivia Bolivianos", @"Brazil Brazil Real", @"Bahamas Dollars", @"Bhutan Ngultrum", @"Botswana Pulas", @"Belarus Rubles", @"Belize Dollars", @"Congo/Kinshasa Congolese Francs", @"Switzerland Francs", @"Chile Pesos", @"China Yuan Renminbi", @"Colombia Pesos", @"Costa Rica Colones", @"Cuba Pesos", @"Cape Verde Escudos", @"Cyprus Pounds", @"Czech Republic Koruny", @"Djibouti Francs", @"Denmark Kroner", @"Dominican Republic Pesos", @"Algeria Algeria Dinars", @"Estonia Krooni", @"Egypt Pounds", @"Eritrea Nakfa", @"Ethiopia Birr", @"Fiji Dollars", @"Falkland Islands Pounds", @"Georgia Lari", @"Guernsey Pounds", @"Ghana Cedis", @"Gibraltar Pounds", @"Gambia Dalasi", @"Guinea Francs", @"Guatemala Quetzales", @"Guyana Dollars", @"Hong Kong Dollars", @"Honduras Lempiras", @"Croatia Kuna", @"Haiti Gourdes", @"Hungary Forint", @"Indonesia Rupiahs", @"Israel New Shekels", @"Isle of Man Pounds", @"India Rupees", @"Iraq Dinars", @"Iran Rials", @"Iceland Kronur", @"Jersey Pounds", @"Jamaica Dollars", @"Jordan Dinars", @"Japan Yen", @"Kenya Shillings", @"Kyrgyzstan Soms", @"Cambodia Riels", @"Comoros Francs", @"North Korea Won", @"South Korea Won", @"Kuwait Dinars", @"Cayman Islands Dollars", @"Kazakhstan Tenge", @"Laos Kips", @"Lebanon Pounds", @"Sri Lanka Rupees", @"Liberia Dollars", @"Lesotho Maloti", @"Lithuania Litai", @"Latvia Lati", @"Libya Dinars", @"Morocco Dirhams", @"Moldova Lei", @"Madagascar Ariary", @"Macedonia Denars", @"Myanmar (Burma) Kyats", @"Mongolia Tugriks", @"Macau Patacas", @"Mauritania Ouguiyas", @"Malta Liri", @"Mauritius Rupees", @"Maldives Rufiyaa", @"Malawi Kwachas", @"Mexico Pesos", @"Malaysia Ringgits", @"Mozambique Meticais", @"Namibia Dollars", @"Nigeria Naira", @"Nicaragua Cordobas", @"Norway Krone", @"Nepal Nepal Rupees", @"New Zealand Dollars", @"Oman Rials", @"Panama Balboa", @"Peru Nuevos Soles", @"Papua New Guinea Kina", @"Philippines Pesos", @"Pakistan Rupees", @"Poland Zlotych", @"Paraguay Guarani", @"Qatar Rials", @"Romania New Lei", @"Serbia Dinars", @"Russia Rubles", @"Rwanda Rwanda Francs", @"Saudi Arabia Riyals", @"Solomon Islands Dollars", @"Seychelles Rupees", @"Sudan Dinars", @"Sweden Kronor", @"Singapore Dollars", @"Saint Helena Pounds", @"Slovenia Tolars", @"Slovakia Koruny", @"Sierra Leone Leones", @"Somalia Shillings", @"Seborga Luigini", @"Suriname Dollars", @"El Salvador Colones", @"Syria Pounds", @"Swaziland Emalangeni", @"Thailand Baht", @"Tajikistan Somoni", @"Turkmenistan Manats", @"Tunisia Dinars", @"Tonga Pa'anga", @"Turkey New Lira", @"Trinidad and Tobago Dollars", @"Tuvalu Dollars", @"Taiwan New Dollars", @"Tanzania Shillings", @"Ukraine Hryvnia", @"Uganda Shillings", @"Uruguay Pesos", @"Uzbekistan Sums", @"Venezuela Bolivares", @"Viet Nam Dong", @"Vanuatu Vatu", @"Samoa Tala", @"Silver Ounces", @"Gold Ounces", @"East Caribbean Dollars", @"Palladium Ounces", @"Platinum Ounces", @"Yemen Rials", @"South Africa Rand", @"Zambia Kwacha", @"Zimbabwe Dollars",nil];
这是一个静态列表......无论何时发生变化。将其用于“查找”样式详细信息视图。
我期待你的想法。 :)
答案 0 :(得分:6)
即使它“永远不会改变”(顺便说一下,jinx),我会把它扔进属性列表并使用arrayWithContentsOfFile:
将其读入静态变量。这使它更具可读性,并且可能让您将其重用于其他事物。
答案 1 :(得分:2)
currencyLabels = [[NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"currencyLabels" ofType:@"plist"]] retain];
数据驱动,因为不需要像这样的硬编码配置,应该可以在不更改代码的情况下更改此类数据。通过NSBundle
加载,以便您可以根据需要本地化plist。保留以匹配示例中显示的对象所有权。
答案 2 :(得分:1)
我还不完全明白你期望得到什么样的答案......如果是为了代码短缺,那么这种方法会有所帮助:
NSString *list = @"Canadian Dollars|Euros|British Pounds...";
NSArray *listItems = [list componentsSeparatedByString:@"|"];
您还可以将列表项目保存到每个条目的文本文件中。将该文件作为字符串加载并用换行符分隔以获取您的项目