Xcode 6.2中尚不支持Swift编译器错误类变量?我该如何解决这个问题

时间:2016-01-23 18:48:08

标签: ios swift xcode-6.2

这是我的commonutils.swift文件夹中的代码。我收到一个错误,说明类变量尚不支持。有人可以帮我理解做什么,以便我可以解决这个问题吗?请

class CommonUtils: NSObject {
  class let cache = NSCache()

  class func clearCache() {
    cache.removeAllObjects()
  }

  class func cacheObject(object: AnyObject, key: String) {
    cache.setObject(object, forKey: key)
  }

  class func cachedObject(key: String) -> AnyObject? {
    return cache.objectForKey(key)
  }

  class func showAlert(title : String, message : String, delegate : NSObject) {
    let alert = UIAlertView(title: title, message: message, delegate: delegate, cancelButtonTitle: "OK")
    alert.show()
  }

  class func showAlert(title : String, message : String, delegate : NSObject, button : String) {
    let alert = UIAlertView(title: title, message: message, delegate: delegate, cancelButtonTitle: button)
    alert.show()
  }

  class func getTextHeight(text: String, width: CGFloat, font: UIFont) -> CGFloat {
    let nsString = NSString(string: text)
    let attributeDict : NSDictionary = NSDictionary(object: font, forKey: NSFontAttributeName)
  }

  class func getWidthOfString(text: String, font: UIFont) -> CGFloat {
    let attributeDict : NSDictionary = NSDictionary(object: font, forKey: NSFontAttributeName)
    let attributedString : NSAttributedString = NSAttributedString(string: text, attributes: attributeDict as [NSObject : AnyObject])
    return attributedString.size().width
  }
}

0 个答案:

没有答案