Swift Tutorial - Tutorialspoint

(backadmin) #1
} else if circumNumber != nil {
return circumNumber
} else {

return nil

}
}
}

let circname = rectangle()
circname.print?[ 0 ] = radius(radiusname: "Diameter")

let printing = circle()
printing.area.append(radius(radiusname: "Units"))
printing.area.append(radius(radiusname: "Meter"))
circname.print = printing

if let radiusName = circname.print?[ 0 ].radiusname {
println("Radius is measured in \(radiusName).")
} else {
println("Radius is not specified.")
}

When we run the above program using playground, we get the following result:


Radius is measured in Units.

In the above program, the instance values for the membership function 'radiusName' is
specified. Hence, the program call to the function will now return values.


Chaining on Methods with Optional Return Values


Optional chaining is used to access subclasses defined methods too.


class rectangle {
var print: circle?
}

class circle {
var area = [radius]()
Free download pdf