1.切割数组
2. 索引+元素遍历法
for (索引+元素) in 数组
for (index,emotion) in model!.enumerate(){
let btn = btnArray[index]
btn.emoticon = emotion
}
字典也可以
相当于oc中的enum_Block遍历
3,排重,和插入数组
/*
排重
1.便利 -可以实现的
2.content
*/
if let emo = emoticon{
// 采用 contains来判断一下数组里 是否有这个表情
if !recentEmoticons.contains(emo){
recentEmoticons.insert(emo, atIndex: 0)
// 最多加20个
if recentEmoticons.count > 20 {
//把多余的最后一个删除
recentEmoticons.removeLast()
}
}