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
  • 相关阅读:
    我的VB之路
    VB 2005 初学者的书-来自MSDN
    腾讯比Groupon更想要
    Google在移动互联网
    HTML5之二认识HTML5
    HTML5之三认识HTML5
    HTML5之一认识HTML5
    SQL 临时表
    通过COM发送邮件而不跳出安全警告
    SSRS报表创建步骤(转载)
  • 原文地址:https://www.cnblogs.com/davidgu/p/4766881.html
Copyright © 2011-2022 走看看