jebmarcus jebmarcus - 5 months ago 22
iOS Question

Swift function does not print

Any idea why this simple piece of code is not printing anything? It should print "A shape with 5 sides"

class shape {

func sides (num: Int) -> String {
return "A shape with \(num) sides"
}

func printResult () {

print(sides(5))

}


}

Answer

If you call it it works

shape().printResult()

Look

enter image description here

By the way the name of a class should start with an uppercase char so Shape instead of shape.

Comments