zoukankan      html  css  js  c++  java
  • Swift学习笔记

    1. Mutability

    Objective-C offers several classes in both “regular” and mutable versions,

    such as NSString/NSMutableString, NSArray/NSMutableArray, and so on.

    In Swift, mutability is determined when you create an instance, not by choice of class.

    An instance is declared as being either a variable or constant, thus establishing whether it can or cannot be changed.

    Variables are declared using the var keyword and are mutable.
    Constants are immutable and declared using the let keyword.

    In Swift, constants are used ubiquitously. Apple advises to always
    declare a stored value as a constant when you know its
    value is not going to change, because doing so aids performance

    eg:

    Variable    var valueThatMayChange = "Hello "
    Constant   let valueThatWillNotChange = "Hello World"

    var greeting: String = "Hello world"
    var greeting = "Hello world"

    以上两种都是可以的,指定和不指定类型

    2. typedef

    Objective-C:

    typedef NSInteger VolumeLevel;
    VolumeLevel volume = 0;

    Swift:

    typealias VolumeLevel = UInt
    let volume = VolumeLevel.min
  • 相关阅读:
    理解cookie
    浏览器解析url后执行过程
    如何使用D3绘制折线图
    Django 笔记
    vi命令
    PEP8编程规范
    Python_入门第一篇【持续更新...】
    DjangoWeb _ 登录页开发test
    Django开发流程
    Django 笔记2018.2.7
  • 原文地址:https://www.cnblogs.com/davidgu/p/4766881.html
Copyright © 2011-2022 走看看