Static methods may only be declared on a type

swift

Solution

The reason I got this error message in a slightly confusing place was that I had a missing close parenthesis earlier in the class.

To the compiler the declaration seemed to be inside another method. For this reason the error message showed up in a place that seemed otherwise to be fine. Error message it self is on point.

This was the first google hit, so I'm adding my experience here in the hopes it will help others who have made a similar mess.

Problem

I am getting an error that says: Static methods may only be declared on a type How can I solve this ? ``` public static func random(min min: CGFloat, max: CGFloat) -> CGFloat { return CGFloat.random() * (max - min) + min } ``` This is how I am calling the above method from the SWIFT class. ``` var ran = CGFloat.random(min:-255, max:588) ```

Original source