Swift: class methods can only be declared by type

I get a compiler error. "Class methods can only be declared for type." I'm not sure why I understand that this is honest. All answers apply to another senario. Any suggestions are welcome.

class func fontWithSize(var size : CGFloat) -> UIFont { let font : UIFont = UIFont (name: "Roboto-Regular", size: size)! return font; } 
+7
ios compiler-warnings swift
source share
1 answer

One thing that looks weird is the var keyword before the parameter name. Another thing; do you declare this method inside the class definition? You are probably getting this error because you are declaring a method on a top or global scale. If this is your intention, you still don't need the class keyword.

+5
source share

All Articles