Play Transfer swift--Study notes (continuous update)

Source: Internet
Author: User

Recently in learning iOS development, take notes down!

    1. Constants and variables

      • Let-constants Constants
let maxNum =32
    • Var-variables variable
varindex0
    • Declare multiple variables at the same time
var x=0.0,y=0.0,z=0.0
    • Types can be inferred, or they can be explicitly declared
var0//这里是一个整形var str:String"123"  //这是一个字符串
    • Basic type
      int (integral type)
      Double,float (floating point)
      String (String)
      BOOL (Boolean type)

    • Number Type
      Decimal
      Binary 0b101
      Octal 0o5
      Hex 0x5

    • Can be counted with science

let0.012let1.2e-2  //值为0.012
    • Numbers can be separated by underscores
let1_000_000let1_0000_0000
    • Type conversions
let1let1.3232let num_c:Double = num_b + Double(num_a)  //此处需要强制转换
    1. Boolean type and if statement

      • The IF can be followed without parentheses, but curly braces are required.

      • The condition cannot be of another type, it must be a Boolean type

trueif isTrue{    println("is true") }else{    println("is false")}
    1. Tuple tuples
      • Set multiple different values to a single data
var registrationResult = (true,"慕课女神","女")let (isRegisterSuccess,nickname,gender) = registrationResultisRegisterSucss   //此处就为truenickname          //"慕课女神"gender            //"女"可以这样取值registrationResult.0   //此处就为trueregistrationResult.1   //"慕课女神"registrationResult.2   //"女"
    • Omit part of a value by an underscore
let (isRegisterSuccess,_,_) = registrationResult
    1. Optionals selectable values

      • Or is a value, or there is no value
      • Nil when there's no value.
a:Int?a                //此时是nila12           //此时是(Some 12)a!               //此时是12 通过!解包
    • Optional binding is unpacked directly
var18iflet yourAge = age{    pringln("\(yourAge)")  }
    1. Base operator

      • Assignment operation
var1var a = b
    • Subtraction, Yu (die)
a530a + ba - ba * ba / b        //此处除数不能为0,求余也不能为0a % bInt.max      //整型的最大值Int.min      //整型的最小值
    • "+ +", "--" self-added self-reduction
varc=0c++c--c+=2
    • Comparison operator (==,! =,>,<,===,!==)

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Play Transfer swift--Study notes (continuous update)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.