A lot of answers seem to be resolving around typos and extra scopes left open or prematurely closed. However, just for the case if some people will meet this issue while deliberately trying to declare a function in global scope as static
, a clarification needs to be made:
All functions in global scope are statically linked inside the executable/library, which is a reason why they are available globally, from any scope, in the first place. However, in the context of an object oriented language, which Swift, undoubtedly, is, the allocation of instances of classes is by design allowed (and expected) to be dynamic, so the actual memory address at which the instance will end up being allocated is unknown ahead of time. So that's what we do - we declare functions as static to explicitly tell the compiler that while this function belongs to this class, it needs to be not bound to a particular instance of class, but the class itself, thus allowing for it being accessed from anywhere. In this regard, we could say that all functions in global scope are implicitly static.
random(min:max:)
to be a type method onCGFloat
, then you need to define it in aCGFloat
extension. – Hamish Oct 22 '16 at 19:13