func setupAvatarColor(name: String, incoming: Bool) {
let diameter = incoming ? UInt(collectionView.collectionViewLayout.incomingAvatarViewSize.width) : UInt(collectionView.collectionViewLayout.outgoingAvatarViewSize.width)
let rgbValue = name.hash
let r = CGFloat(Float((rgbValue & 0xFF0000) >> 16)/255.0)
let g = CGFloat(Float((rgbValue & 0xFF00) >> 8)/255.0)
let b = CGFloat(Float(rgbValue & 0xFF)/255.0)
let color = UIColor(red: r, green: g, blue: b, alpha: 0.5)
**let nameLength = count(name);**
let initials : String? = name.substringToIndex(advance(sender.startIndex, min(3, nameLength)))
let userImage = JSQMessagesAvatarFactory.avatarWithUserInitials(initials, backgroundColor: color, textColor: UIColor.blackColor(), font: UIFont.systemFontOfSize(CGFloat(13)), diameter: diameter)
avatars[name] = userImage
}
I receiving the error '`String is not convertible to Range<I>'in the highlighted code (10th line)`. AnyOne?
最佳答案
在 Swift 2 中,Apple 删除了很多全局函数。
在您的情况下,要获取字符串的长度,请执行以下操作:
str.characters.count
关于ios - String is not convertible to Range<I> swift anyone 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33146487/