zoukankan      html  css  js  c++  java
  • iOS-初识swift

    在学习iOS开发之前,先掌握一点swift知识是必要的。
    note:不论是iOS开发还是编程语言的学习,都应该是迭代、由浅入深的过程,是理论实践相结合的过程。

    中文文档 swift3(与swift4稍有不同,多写代码实操练习即可)
    http://special.csdncms.csdn.net/the-swift-programming-language-in-chinese/Introduction.shtml

    http://wiki.jikexueyuan.com/project/swift/chapter1/chapter1.html

    官方文档 swift4
    https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/TheBasics.html#//apple_ref/doc/uid/TP40014097-CH5-ID309

    内容确实挺多的,需要多次迭代学习整理,记得在有基础之后,多应用、多看sample code。学语言要买书,真的算了吧,中文版的swift参考书,真的都很扯,要么就是挤出罗列,要么就是官方文档无脑译。

    下面罗列一下要点

    #outline#
    变量、类型;运算符、关键字;控制流;函数;面向对象

    一、变量 类型
    declare
    var welcomeMessage: String
    feature:type safe, type inference
    var tmp = "iamcoming"

    optional
    Int Int? Int!
    解包语句
    可选链

    three primary collection types, Array, Set, and Dictionary, as described in Collection Types.
    了解定义、调用属性和方法、如何遍历

    二、运算符 关键字
    type casting
    关键字 is as as! as?


    三、控制流
    循环 for-in

    switch

    三、function
    define
    无参、多参、多返回值的函数

    func someFunction(argumentLabel parameterName: Int) {
    }

    返回值
    func minMax(array: [Int]) -> (min: Int, max: Int)? {
    if array.isEmpty
    { return nil }
    else
    { return (12,13)}
    }

    Default Parameter Values

    In-Out Parameters
    Function parameters are constants by default.
    func swapTwoInts(_ a: inout Int, _ b: inout Int) {
    let temporaryA = a
    a = b
    b = temporaryA
    }

    Function Types
    相当于函数指针
    var mathFunction: (Int, Int) -> Int = addTwoInts

    Every function in Swift has a type, consisting of the function’s parameter types and return type. You can use this type like any other type in Swift, which makes it easy to pass functions as parameters to other functions, and to return functions from functions.

    四、枚举类型
    原来枚举类型还有这么多可以讲的
    raw value、关联值、递归定义


    五、类和结构体
    计算属性、属性观察器

    六、protocol

  • 相关阅读:
    状态机的常见问题
    基于quartus的高级时序分析
    FPGA中的时钟域问题
    quartus中的时序约束常用方法
    时序约束与时序分析
    FPGA的PCB设计
    AXI4的主机协议代码分析
    selenium 笔记 场景判断
    Codeforces Round #676 (Div. 2) XORwice、Putting Bricks in the Wall、Palindromifier
    Trap HDU
  • 原文地址:https://www.cnblogs.com/ceo1207/p/7159514.html
Copyright © 2011-2022 走看看