Swift學習筆記(二十四)——常量數組和常量字典__Swift

來源:互聯網
上載者:User

     同Swift中的其他資料類型一樣,數組和字典也可以分別定義為var,let,也就是變數和常量。定義為let常量的數組和字典都是不可變的。下面來簡單看一下:

import UIKitlet courses_dict = [1:"高等數學",2:"大學英語",3:"程式設計"]  //常量let course_array = ["高等數學","大學英語","程式設計"]   //常量courses_dict.removeValueForKey(3)    //報錯,不能刪除courses_dict.updateValue("四六級", forKey: 2)  //報錯,不能修改courses_dict[4] = "四六級"    //報錯,不能插入course_array.removeAtIndex(0)  //報錯,不能刪除course_array[1] = "四六級"   //報錯,不能修改course_array[3] = "線性代數"  //報錯,不能插入


github首頁:https://github.com/chenyufeng1991  。歡迎大家訪問。

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.