作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
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/
我是一名优秀的程序员,十分优秀!