quattro_4 scribble

scribble 落書き (調べた事をただ落書きする)

NSScreencast Episode #127 Swift Operators

Swift Operators - NSScreencast

SwiftでOperatorを定義 =~

  • be guard
  • init
    • The Swift Programming Language: Initialization
    • initとfuncで引数の扱いが違う
    • external first argument
      • struct Celsius
        • init(fromFahrenheit fahrenheit: Double)
          • Celsius(fromFahrenheit: 212.0)
        • init(fromKelvin kelvin: Double)
          • Celsius(fromKelvin: 273.15)
    • 暗黙の引数
      • underscore (_) as an explicit external name
      • class Regex
        • init(_ pattern: String)
        • Regex("^\d+$")
          • init(pattern: String) の定義だとエラー
  • class Regex
    • func test(input: String) -> Bool {
      • let range = input.rangeOfString(pattern, options: .RegularExpressionSearch)
      • return range.getLogicValue()
  • operator infix =~ {}
    • func =~(input: String, pattern: String) -> Bool {
      • return Regex(pattern).test(input)
    • if input =~ "^\d+$" {
  • operator infix .. {}
    • func ..(a: Vector, b: Vector) -> Float {
      • return a.dotProduct(b)
    • let result = a .. b
  • =~ equal squiggle
    • squiggle 短い不規則な曲線,くねった線
  • The Swift Programming Language: Advanced Operators
    • Swift gives you the freedom to define your own custom infix, prefix, postfix, and assignment operators