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
  • 相关阅读:
    实训-涉及前端的一些小总结
    实训-mybatis-经验总结2
    实训-mybatis-经验总结
    中软实训笔记
    jsp 中JSTL遇到的报错异常
    mysql的小发现
    Maven笔记
    springmvc-3-拦截器
    springmvc 上传图片
    springmvc
  • 原文地址:https://www.cnblogs.com/davidgu/p/4766881.html
Copyright © 2011-2022 走看看