如果我正确理解你目前的结构:
@interface Emoji : NSObject
@property (nonatomic, strong) NSString *image; //I'd expect a UIImage there and not an image name
@property (nonatomic, strong) NSArray *codes;
@end
@interface Emoji : NSObject
@property (nonatomic, strong) NSString *image; //I'd expect a UIImage there and not an image name
@property (nonatomic, strong) NSString *code;
@end
self.emojis
会有很多
Emoji
对于不同的代码,对象可能具有相同的图像名称,但这样做的一个优点是这个小技巧:
排序
自我情感
在某种程度上,“较小”的表情是在最后。所以你要先替换“长的”和小的。
self.emojis = [arrayOfSingleEmojis sortedArrayUsingComparator:^NSComparisonResult(Emoji * _Nonnull emoji1, Emoji * _Nonnull emoji2) {
NSUInteger length1 = [[emoji1 code] length];
NSUInteger length2 = [[emoji2 code] length];
return [@(length2) compare:@(length1)]; //Or reverse length1 & length2, I never know, I always have to test, but I think it's the correct one
}];
]:-)
将在
:-)
<imageFor:">:-)"]
而不是
]<imageFor:":-)>