20210205 이론 공부 : 실제 코딩 : 타인 코드 읽는 시간 = 1: 1 : 1

NOAH·2021년 2월 5일
0

TIL

목록 보기
11/179
post-thumbnail

코딩나라 입국 31일

  • 공부하는 비율을 (이론 공부 : 실제 코딩 : 다른 사람 코드 읽는 시간)을 너무 한 쪽에 편중되지 않도록 균형을 맞추어 주는 것이 중요하다는 것을 느꼈다.

  • Swift 문서보면서 기본 문법을 익히고 있는데, 일반 영어에 가까워서 재밌었다. 타입 선언하지 않고 리터럴을 할당하면 스위프트가 알아서 타입을 지정해주고, tuple은 데이터 타입에 관계없이 넣을 수 있는 배열 같았다. 신세계다.

//variable
var firstname = "Noah";
print(firstname);
// constant
let lastname = "Lee";
/*
 1. Varibles and constants are used to keep track of the data in your app
    Constants are like variables but you can't reassingn data to them after the initial assignment.
 
 2. Use "var" and "let" keywords to declare new variables and constants
 
 3. Use uqual signs to assign data to a variable or constant
 
 4. Use camel case as the best practice for naming variables or constants
 
 5.
 */

//Data .Type

var str:String = "Hello, playground" ;
var aFloat:Float = 0.23 ;
var aDouble:Double = 1.124 ;
var aBool:Bool = true;
print(aDouble);


// Tuple : multiple values into a single compound value
let http404Error = (404, "Not Found")
//It can be described as " A Tuple of type(Int, String)"


//You can decompose a tuple's contents into seperate constants or variable,
//whih you then access as usual

let (statusCode, statusMessages) = http404Error
print("The status code is \(statusCode)") // The status code is 404
print("The status message is \(statusMessages)") //The status message is Not Found

/*
 If you only need some of tuple's value, ignores parts of the tuples with andorscore(_)
 when you decompose the tuple
 */

let (justStatusCode, _) = http404Error
print("the status code is \(justStatusCode)") //the status code is 404

/*
 Alternatively, access the individual element values in a tuple
 using index numbers starting at zero:
 */

print("The status code is \(http404Error.0)") // the status code is 404
print("The status code is \(http404Error.1)") // The status code is Not Found

/*
 You can name the individual elements in a tuple when the tuple is defined:
 */

let http200Status = (statusCode: 200, description:"OK")

/*
 If you name the elements in a tuple,
 you can use the element names to access the values of those elements:
 */

print("The status code is \(http200Status.statusCode)")
print("THe description is \(http200Status.description)")



/*
 Tuples are particularly useful as the return values of functions.
 A function that tries to retrieve a web page might return the (Int, String) tuple type
 to describe the success or failure of the page retrieval. By returning a tuple
 with two distinct values, each of a different type, the function provides more useful information
 about its outcome than if it could only return a single value of a single type.
 */

1개의 댓글