Don't understand a particular code snippet

import Foundation

public enum ShapeType:Int {
case Box = 0
case Sphere
case Pyramid
case Torus
case Capsule
case Cylinder
case Cone
case Tube

static func random() → ShapeType {
//1 let maxValue = Tube.rawValue
//2 let rand = arc4random_uniform(UInt32(maxValue+1))
//3return ShapeType(rawValue: Int(rand))!
} }

I am a complete beginner to iOS development,so pardon me.
Hey,I don’t understand the what is the point of ‘static’. Can anyone also explain to me clearly on what do each of the three lines in the ‘random’ function do. Thanks!

If you still wondering… static means that the method is accessible across the Type itself instead of an instance of type. So that you just call ShapeType.random(), without declaring any object. This enum contains keys corresponding to int raw values. You can get it by two things: The declaration (ShapeType: Int) and the first case Box = 0. Thanks to Swift type inference, and to an old C convention, since Box starts being equal to 0, each case is upper of 1, so Sphere is 1, Pyramid is 2, and finally Tube is 7.
The function gets Tube.rawValue, which is 7 (the real value of Tube in Swift is corresponding to a hash). Give to rand constant a random value from 0 to maxValue. How does it get it? Well the functions applies this calculation… Get a random value and MOD it to maxValue+1. So if the number generated was 8, 8 mod 8 = 0. If it was 111 mod 8 = 7, etc.

So this value can just be among 0 and 7.

Then it finally returns the corresponding case to the given random number (remember that case real values are hashes, so you can’t return their raw values pretending the value is still of type enum).

Hope I clarified it. You should also considering on taking a Swift book/course because this book won’t explain you basic Swift but will act like you already know it.