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
  • 相关阅读:
    Openlayer 3 的画图测量面积
    Openlayer 3 的画线测量长度
    屏幕尺寸
    px和em,rem的区别
    水平和垂直居中
    Flex布局
    继承的几种方法及优缺点
    call ,apply 和 bind的用法与区别
    mybatis springmvc velocity的demo
    正则同时包含两个关键字
  • 原文地址:https://www.cnblogs.com/davidgu/p/4766881.html
Copyright © 2011-2022 走看看