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

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 :: ios tableview hide empty cells 
Swift :: swift variables 
Swift :: how to darken view swiftui 
Swift :: swift output 
Swift :: swift api call with certificate 
Swift :: enums With Raw Values Swift 
Swift :: swift looping through array 
Swift :: swift converting time string to number 
Swift :: Swift Escape Sequences 
Swift :: how to have diffrent size images in a stack view swift 
Swift :: swift weekday date component values 
Swift :: image copy swift extension 
Swift :: swift how to append an element 
Swift :: add placeholder to code snippets xcode 
Swift :: get files with file type swift 
Swift :: swift get all cases starting with 
Swift :: swiftUI parse json from url 
Swift :: display toast in xamarin IOS 
Ruby :: how to get tables list in rails 
Ruby :: rails remove column from model 
Ruby :: ruby current date and time 
Ruby :: rails migration polymorphic references 
Ruby :: run a specific migration rails 
Ruby :: rails change date format 
Ruby :: ruby unshift method 
Ruby :: date time string to time in rails 
Ruby :: iterate through values of an object rails 
Ruby :: preview mailers rails 
Ruby :: ruby check if constant exists 
Ruby :: ruby conditionals 
ADD CONTENT
Topic
Content
Source link
Name
8+8 =