Structures and Classes

Run Settings
LanguageSwift
Language Version
Run Command
struct SomeStructure { // structure definition goes here } class SomeClass { // class definition goes here } struct Resolution { var width = 0 var height = 0 } class VideoMode { var resolution = Resolution() var interlaced = false var frameRate = 0.0 var name: String? } print("The width of someResolution is \(someResolution.width)") // Prints "The width of someResolution is 0" print("The width of someVideoMode is \(someVideoMode.resolution.width)") // Prints "The width of someVideoMode is 0" let vga = Resolution(width: 640, height: 480) let hd = Resolution(width: 1920, height: 1080) var cinema = hd cinema.width = 2048 print("cinema is now \(cinema.width) pixels wide") // Prints "cinema is now 2048 pixels wide" print("hd is still \(hd.width) pixels wide") // Prints "hd is still 1920 pixels wide" //CONTOH enum CompassPoint { case north, south, east, west mutating func turnNorth() { self = .north } } var currentDirection = CompassPoint.west let rememberedDirection = currentDirection currentDirection.turnNorth() print("The current direction is \(currentDirection)") print("The remembered direction is \(rememberedDirection)") // Prints "The current direction is north" // Prints "The remembered direction is west" // let tenEighty = VideoMode() tenEighty.resolution = hd tenEighty.interlaced = true tenEighty.name = "1080i" tenEighty.frameRate = 25.0 let alsoTenEighty = tenEighty alsoTenEighty.frameRate = 30.0 print("The frameRate property of tenEighty is now \(tenEighty.frameRate)") // Prints "The frameRate property of tenEighty is now 30.0" Identical to (===) Not identical to (!==) if tenEighty === alsoTenEighty { print("tenEighty and alsoTenEighty refer to the same VideoMode instance.") } // Prints "tenEighty and alsoTenEighty refer to the same VideoMode instance."
Editor Settings
Theme
Key bindings
Full width
Lines