Swift Compiler Error Class Variable not yet supported in Xcode 6.2? How to I fix this

139 views Asked by At

This is the code in my commonutils.swift folder. I am getting an error stating class variable not yet supported. Can someone help me to understand what to do so that I can fix this? Please

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

There are 0 answers