2020/09

    [Swift] 스위프트 readLine() 파헤치기

    사용자가 입력하는 다양한 값을 받기 위한 Swift의 readLine( )에 대해 알아보자! 사실 알고리즘 풀이하는데, 코드 도입부에서 가장 많이 등장하는... 함수여서 익힐 필요가 있을 것 같다. Apple 공식문서내 정의를 보면, 먼저 표준 입력을 받아 "문자열"로 반환한다는 것을 알 수 있다. 우리가 Int 타입을 입력하던, Double 타입을 입력하던 간에, 모두 String으로 반환한다. 이 점에 주의하여 입력한 데이터를 입맛에 맞게 데이터 타입을 변환하여 사용해주면 된다. 표준입력은 현재 입력하는 라인의 끝 혹은 EOF(End Of File)에 닿을 때 까지라고 정의하고 있다. EOF란 파일의 끝을 만났음을 알리기 위해 매크로로 정의된 값이다. 간단하게 생각하면 입력하는 값들을 전부 받아 반환..

    [Swift] Swift 값 입력, 비교

    Alice and Bob each created one problem for HackerRank. A reviewer rates the two challenges, awarding points on a scale from 1 to 100 for three categories: problem clarity, originality, and difficulty.The rating for Alice's challenge is the triplet a = (a[0], a[1], a[2]), and the rating for Bob's challenge is the triplet b = (b[0], b[1], b[2]).The task is to find their comparison points by compar..

    [Swift] Array의 Sum 구하기

    Given an array of integers, find the sum of its elements.For example, if the array , , so return .Function DescriptionComplete the simpleArraySum function in the editor below. It must return the sum of the array elements as an integer.simpleArraySum has the following parameter(s):ar: an array of integersInput FormatThe first line contains an integer, , denoting the size of the array. The second ..

    [Swift] URLSession이란? (2)

    URLSession (2)response 받은 데이터를 object로 만들어 볼 것이다.블로그 내의 데이터를 받아와보려고 했으나, 구조가 많이 달라 우선 강의과 같은 조건으로 진행해보자. 우선 기존에 작성했던 것 처럼 urlComponents를 생성한다. let config = URLSessionConfiguration.defaultlet session = URLSession(configuration: config) // URLvar urlComponents = URLComponents(string: "https://itunes.apple.com/search?")!let mediaQuery = URLQueryItem(name: "media", value: "music")let entityQuery = U..

    [Swift] URLSession이란? (1)

    URLSession앱과 서버간에 데이터를 주고 받기 위해서는 HTTP를 이용했었다. 실제 iOS에서는 HTTP를 이용한 네트워킹을 어떻게 할까? 바로 URLSession을 활용하여 수행할 수 있다.URLSession은 URLSessionConfiguration을 통해 생성하게 된다. 또한 URLSession은 여러 개의 URLSessionTask를 만들 수 있다. 이를 통해 실제 서버와의 통신을 하며, Delegate를 통해 네트워크 중간 과정을 확인해볼 수 있다. 또한 URLSessionConfiguration을 통해 다음 세 가지 유형의 URL을 생성할 수 있다,.default : 기본 통신을 할 때 사용이 된다. (쿠키와 같은 저장 객체를 사용한다.).ephemeral : 쿠키나 캐시를 저장하지 않..