这就是
我初始化它的方式:
@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
?
@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];
当需要基元类型,但提供了指针时,会出现此问题。
下面的代码对我来说工作正常。试试吧。
@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];
另请参阅此链接