这是我初始化它的方式:
@property (strong, nonatomic) NSMutableDictionary<NSString *, UIImage *> *images;
这是我插入的方式:
NSString *stringDate = [self getddMMyyyyInString:firstDate]
[[self.images setObject:[UIImage imageNamed:@"rsz_fill.png"] forKey:stringDate]];
我得到的错误是
索引表达式无效,因为下标类型void不是 积分或目标c指针类型
如何将NSString
和UIImage
插入NSmutabledictionary
?
答案 0 :(得分:2)
@property (strong, nonatomic) NSMutableDictionary<NSString *, UIImage *> *images;
self.images = [NSMutableDictionary new];
NSString *stringDate = [NSString stringWithFormat:@"%@", [NSDate date]];
UIImage *image = [UIImage imageNamed:@"rsz_fill.png"];
[self.images setObject:image forKey:stringDate];
答案 1 :(得分:0)
当期望基本类型但提供指针时会发生此问题。
下面的代码对我来说很好。试试吧。
@property (strong, nonatomic) NSMutableDictionary<NSString *, UIImage *> *images;
//inside some method (say viewDidLoad)
NSString *stringDate = [NSString stringWithFormat:@"%@", [NSDate date]];
[self.images setObject:[UIImage imageNamed:@"someImage.png"] forKey:stringDate];
另请参阅此link