我正在更改我的应用程序,以便它可以通过 AFNetworking 解析我的 JSON,当我尝试使用 dateFormatter 更改日期字符串时出现错误。我有一个名为“UpcomingRelease”的NSObject ,一个名为“ UpcomingReleasesViewController”的CollectionViewController和一个名为“ReleaseViewController”的destinationViewController
这是我的旧代码:
* 即将发布.h
@interface UpcomingRelease : NSObject
@property (nonatomic, strong) NSString *release_date;
- (NSString *) formattedDate;
@end
* 即将发布.m
- (NSString *) formattedDate {
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"];
NSDate *newDate = [dateFormatter dateFromString:self.release_date];
[dateFormatter setDateFormat:@"MMMM dd"];
return [dateFormatter stringFromDate:newDate];
}
* ReleaseViewController.h (destinationViewController)
#import "UpcomingRelease.h"
@property (strong, nonatomic) NSDictionary *singleRelease;
@property (weak, nonatomic) IBOutlet UILabel *release_date;
* ReleaseViewController.m
@synthesize singleRelease = _singleRelease;
@synthesize release_date = _release_date;
- (void)viewDidLoad
{
[super viewDidLoad];
if([_singleRelease objectForKey:@"release_date"] != NULL)
{
self.release_date.text = [NSString stringWithFormat:@"%@", _singleRelease.formattedDate];
}
else
{
self.release_date.text = [NSString stringWithFormat:@"Releasing Soon"];
}
}
我收到一条错误消息,提示“在 'NSDictionary' 类型的对象上找不到属性 'formattedDate')。