본문 바로가기

Programming40

[Swift] Optional Swift 에서는 Safe Power Modern 을 강조했다.이중에서 Optional 은 Safe 에 해당하는 문법이다. Optional 은 아래와 같다. // OPTIONALS/*OPTIONAL is for Safety code !Optional은 nil이 될 수도 있는 변수를 의미하고 선언할 때 ?를 사용한다. 일반적인 선언의 경우 Non-Optional 이며 nil이 될 수 없다.*/var score : Int? //score = 21 // forced unwrapping//print("The score is currently \(score!)") if score != nil { print("The score is currently \(score)")}else{ print("Could not ge.. 2016. 2. 10.
[Swift] Tuple 이번에는 튜플에 대해서 공부하였습니다.튜플은 기존의 NS 시스템에서는 볼 수 없었던 특이한 점입니다.아래의 예를 보시면요. unamedTuple 의 경우 키값이 없는 튜플이고.var unamedTuple = (123,455) namedTuple 의 경우에는 키값이 존재하는 튜플입니다. var namedTuple = (first:123,second:455) 튜플은 쉽게 생각하면 딕셔너리갖다고 생각하시면 될것 같습니다. 다만, 다르게 느껴지는 점이라면요.딕셔너리에서는 키값을 인덱스로 가져다 쓴다면.이녀석은 자바스크립트에서 정의한 배열의 느낌이 강합니다.class 같은 느낌이 좀 더 강합니다. // 2016. 02. 10. Ruke// TUPLES var products = [123: "Bananas",234.. 2016. 2. 10.
[Swift] Set Swift provides three primary collection types, known as arrays, sets, and dictionaries, for storing collections of values. Arrays are ordered collections of values. Sets are unordered collections of unique values. Dictionaries are unordered collections of key-value associations. 시작하기에 앞서 다음은 Apple Document 에서 명시되어 있는 설명이다.요약하면.. Array,: 정렬된 값들의 집합Set : 정렬되지 않은 값들의 집합Dictionary : 정렬되지 않은 key-valu.. 2016. 2. 10.
[Swift] Dictionary Swift 에서 딕셔너리 형을 어떻게 사용하는지 보았는데이건 완전 자바스크립트다... 우와..편해.. // 2016. 02. 10. Ruke // Dictionaries var emptyDictionary = [String:String]() var states = ["NJ":"New Jersey","NY":"New York","CA":"California","FL":"Florida","TX":"Texas"] states.count states["NY"] = nil states["NY"] = "New York" states //states.updateValue("NYork", forKey: "NY")states["NY"] = "NYs" states var products = [123:"Apples",234.. 2016. 2. 10.
반응형