gpt4 book ai didi

ios - String is not convertible to Range swift anyone 错误

转载 作者:行者123 更新时间:2023-11-28 13:04:30 24 4
gpt4 key购买 nike

 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com