Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift: class methods may only be declared on a type

I am getting the compiler error "Class methods may only be declared on a type". I am not sure why I am getting this to be honest. All the stack overflow answers apply to another senario. Any suggestions are appreciated.

       class func fontWithSize(var size : CGFloat) -> UIFont
       {
       let font : UIFont = UIFont (name: "Roboto-Regular", size: size)!
       return font;
       }
like image 365
user3606054 Avatar asked Jan 13 '15 19:01

user3606054


1 Answers

One thing that looks odd is the var keyword in front of the parameter name. The other thing; are you declaring this method inside a class definition? You're probably getting this error because you're declaring the method at the top-level or global scope. If that's your intention the you don't need the class keyword anyway.

like image 119
Jernej Strasner Avatar answered Oct 28 '22 14:10

Jernej Strasner