[英]'[String]' is not convertible to '[NSString]'
I am following the tutorial on this link: http://www.raywenderlich.com/97014/use-cocoapods-with-swift 我正在此链接上关注该教程: http : //www.raywenderlich.com/97014/use-cocoapods-with-swift
According to Xcode, there is an error on the line 根据Xcode,在线上有错误
var components = (string as NSString).componentsSeparatedByString(",") as! [NSString]
It says that '[String]' is not convertible to '[NSString]'. 它说“ [String]”不能转换为“ [NSString]”。 What is happening exactly, and how should I fix it?
到底发生了什么,该如何解决?
Thanks! 谢谢! Here is the code:
这是代码:
import UIKit
func RGB(red: CGFloat, green: CGFloat, blue: CGFloat) -> UIColor {
return RGBA(red, green: green, blue: blue, alpha: 255)
}
func RGBA(red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat) -> UIColor {
return UIColor(red: red/255, green: green/255, blue: blue/255, alpha: alpha/255)
}
extension UIColor {
class func RGBAColorFromString(string: String?) -> UIColor? {
if let string = string {
var components = (string as NSString).componentsSeparatedByString(",") as! [NSString]
if components.count == 3 {
components.append("1.0")
}
if components.count != 4 {
return nil
}
let red = CGFloat(components[0].floatValue / 255)
let green = CGFloat(components[1].floatValue / 255)
let blue = CGFloat(components[2].floatValue / 255)
let alpha = CGFloat(components[3].floatValue / 255)
return UIColor(red: red, green: green, blue: blue, alpha: alpha)
}
return nil
}
}
它使用以下语法:
var components = string.componentsSeparatedByString(",") as [NSString]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.