Skip to content

Function(Swift4.2)

   

This is how to create a function in Swift. Lately, I've been able to write without even looking at online articles.

import UIKit
// 横幅と縦幅から面積を計算
func area(height: Double, width: Double) -> Double {
return height * width
}
// 引数名と関数の中での変数名が異なる
func area2(height h: Double, width w: Double) -> Double {
return h * w
}
// 引数名を省略
func area3(_ h: Double, _ w: Double) -> Double {
return h * w
}
// 面積を求める
print(area(height: 3.00, width: 3.00))
print(area2(height: 3.00, width: 3.00))
print(area3(3.00, 2.00))
// 参照渡し
func double(_ x: inout Int) {
x = x * 2
}
var x = 100
var y = 0
print("x = \(x)")
// x = 100
double(&x)
print("x = \(x)")
// x = 200
view raw Function.swift hosted with ❤ by GitHub

  1. Array(Swift4.2)
  2. Print(Swift4.2)
  3. Search the contents of UITableView with UISearchBar(Swift4)
  4. Obtaining location information while using the app
  5. The interaction of the Lifesum app was nice, so I tried to recreate it.
  6. 押すとクニュっとするボタンを実装する
  7. Docker image that can be SSHed in(Ubuntu14.04)