【发布时间】:2014-06-13 10:36:28
【问题描述】:
我有以下imageMap 在名为Class 的Class 中返回NSDictionary,称为WXCondition:
+ (NSDictionary *)imageMap {
// 1
static NSDictionary *_imageMap = nil;
if (! _imageMap) {
// 2
_imageMap = @{
@"01d" : @"weather-clear",
@"02d" : @"weather-few",
@"03d" : @"weather-few",
@"04d" : @"weather-broken",
@"09d" : @"weather-shower",
@"10d" : @"weather-rain",
@"11d" : @"weather-tstorm",
@"13d" : @"weather-snow",
@"50d" : @"weather-mist",
@"01n" : @"weather-moon",
@"02n" : @"weather-few-night",
@"03n" : @"weather-few-night",
@"04n" : @"weather-broken",
@"09n" : @"weather-shower",
@"10n" : @"weather-rain-night",
@"11n" : @"weather-tstorm",
@"13n" : @"weather-snow",
@"50n" : @"weather-mist",
};
}
return _imageMap;
}
然后我有以下方法返回 imageMap 方法:
- (NSString *)imageName {
return [WXCondition imageMap][self.icon];
}
我正在尝试将这些方法转换为 Swift,到目前为止我有以下内容:
func JSONKeyPathsByPropertyKey() -> NSDictionary {
return {
"date": "dt",
"locationName": "name",
"humidity": "main.humidity",
"temperature": "main.temp",
"tempHigh": "main.temp_max",
"tempLow": "main.temp_min",
"sunrise": "sys.sunrise",
"sunset": "sys.sunset",
"conditionDescription": "weather.description",
"condition": "weather.main",
"icon": "weather.icon",
"windBearing": "wind.deg",
"windSpeed": "wind.speed"
}
}
func imageName() -> NSString {
return "" //[WXCondition imageMap][self.icon];
}
不太清楚如何正确返回NSDictionary。
【问题讨论】:
标签: objective-c nsdictionary swift