Search
 
SCRIPT & CODE EXAMPLE
 

SWIFT

switch statements swift

var x = 1

switch x {
  case 0: // if x = 0
  	print("x = 0")
  case 1: // if x = 1
  	print("x = 1")
  default: // if x is not 0 nor 1
  	print("no x value")
}
Comment

switch case in swift language

let liveAlbums = 2

switch liveAlbums {
case 0:
    print("You're just starting out")

case 1:
    print("You just released iTunes Live From SoHo")

case 2:
    print("You just released Speak Now World Tour")

default:
    print("Have you done something new?")
}
Comment

swift switch

for i in 1 ... 100 {
    switch (i % 3, i % 5) {
    case (0, 0):
        print("FizzBuzz")
    case (0, _):
        print("Fizz")
    case (_, 0):
        print("Buzz")
    default:
        print(i)
    }
}
Comment

Swift switch Statement

switch (expression)  {
  case value1:
    // statements 

  case value2:
    // statements 

  ...
  ...
        
  default:
    // statements
}
Comment

Swift Tuple in Switch Statement

let info = ("Dwight", 38)

// match complete tuple values
switch info {
  case ("Dwight", 38): 
    print("Dwight is 38 years old")

  case ("Micheal", 46): 
    print("Micheal is 46 years old")

  default:
    print("Not known")
}
Comment

PREVIOUS NEXT
Code Example
Swift :: swift lazy 
Swift :: swiftui rounded specific corner 
Swift :: swft view 
Swift :: struct vs class in swift 
Swift :: value to value in sum 
Swift :: Swift Half-Open Range 
Swift :: clothes that you wear in Diwali 
Swift :: swift 5 touchupinsideview 
Swift :: repeat...while Loop Swift 
Swift :: swift disable modal dismiss swift 
Swift :: Swift Initializer 
Swift :: Swift Computed Property In Extension 
Swift :: Swift Tuple in Switch Statement 
Swift :: SwiftUI cant tap in spacer of HStack 
Swift :: Swift Function overloading with Argument Label 
Swift :: swiftui polygon 
Swift :: swiftui button only text tappable 
Swift :: Swift guard with multiple conditions 
Swift :: view rounded corners swift 
Swift :: Named Associated Values Swift 
Swift :: swiftui orientation failed after change orientation popup 
Swift :: Swap/Change Rootviewcontroller with Animation ios/swift 
Swift :: circular array swift 
Ruby :: ruby json parse symbolize_keys 
Ruby :: dotenv-rails comments 
Ruby :: ruby print string 
Ruby :: contains ruby array 
Ruby :: ruby string to int 
Ruby :: parse xml ruby 
Ruby :: ruby remove last element of string 
ADD CONTENT
Topic
Content
Source link
Name
4+7 =