Skip to content

Latest commit

 

History

History
39 lines (37 loc) · 2.08 KB

Types.md

File metadata and controls

39 lines (37 loc) · 2.08 KB

Types

  • Swift

    • In swift, both reference types and value types are supported.
      // Value type example
      struct S { var data: Int = -1 }
      var a = S()
      var b = a						// a is copied to b
      a.data = 42						// Changes a, not b
      println("\(a.data), \(b.data)")	// prints "42, -1"
    
      // Reference type example
      class C { var data: Int = -1 }
      var x = C()
      var y = x						// x is copied to y
      x.data = 42						// changes the instance referred to by x (and y)
      println("\(x.data), \(y.data)")	// prints "42, 42"
    

    Swift goes a step further to categorize into two data types, named types and compound types.

    • A named type is a type that can be given a particular name when it is defined. Named types include classes, structures, enumerations, and protocols
    • A compound type is a type without a name, defined in the Swift language itself. There are two compound types: function types and tuple types.
  • Java