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 :: two integer variable in swift 
Swift :: variable sum in swift 
Swift :: Swift Named Tuples 
Swift :: swiftui selection list 
Swift :: clothes that you wear in Diwali 
Swift :: tap to delete xcode 
Swift :: Swift Double 
Swift :: swift from 1 to 01 
Swift :: Working of Recursion in Swift 
Swift :: how to screen record swift stackoverflow 
Swift :: while loops swift 
Swift :: procedural audio with swift 
Swift :: Swift Function With inout Parameters 
Swift :: Swift Optional Binding (if-let 
Swift :: special symbol ios swift 
Swift :: how to have diffrent size images in a stack view swift 
Swift :: Swift Find Number of Dictionary Elements 
Swift :: Notification Service Extension vs Content Extension 
Swift :: swift string pad 
Swift :: dynamic table view height without scrolling 
Swift :: Swift Bitwise OR Operator 
Swift :: display toast in xamarin IOS 
Ruby :: button with icon rails 
Ruby :: frozen string literal ruby 
Ruby :: ruby constructor 
Ruby :: ruby file get line number 
Ruby :: how to get current month end date in ruby 
Ruby :: ruby different ways to run string interpolation 
Ruby :: rails resources only 
Ruby :: date class to unix timestamp ruby 
ADD CONTENT
Topic
Content
Source link
Name
6+2 =