Posts

Showing posts with the label Class

Swift Class versus Structure

In Swift Just like classes play a important role , Structure do play a important role. What could be the notable difference? First one is Structure is pass by value and Classes are pass by reference.  Below is a simple example to understand the meaning of it. func getAddress( _ object: Any )-> String {     var newObject = object     var address: String = String ( "Could Not CalculateAddress" )     withUnsafePointer (to: &newObject) {                  address = " \ ( $0 )"     }     return address } func getAddressForClass( _ object: AnyObject ) -> Any {     return Unmanaged < AnyObject >. passUnretained (object). toOpaque () } //Structure struct User{     var name: String     var userId: Int } func changeStructuredValue( _ inputStruct: User ){     var newI...