Avatar ·

What is the difference between static func and class func in Swift?

Hello! I started learning Swift and came across two similar ways to declare methods that belong to the type itself, not its instance. Using the `static` keyword before `func`, I can call a method without creating an object. But I also saw that you can use `class func` for the same purposes. For example: ```swift struct MyStruct { static func sayHello() { print("Hello from static!") } } class MyClass { class func sayHello() { print("Hello from class!") } } ``` Both calls work: `MyStruct.sayHello()` and `MyClass.sayHello()`. What is the fundamental difference between them? Why can't we just use `static` everywhere? And are there any restrictions on using `static` in classes? I would be grateful for a detailed explanation with examples.