목록앱 개발/iOS (96)
나의 발자취
Syntatic sugar란?컴퓨터과학에서 사용하는 용어로, 좀 더 쉽게 읽고 쓸 수 있는 syntax를 말한다.스위프트에서 배열을 만들 때 Array보다 [Int] 가 더 직관적으로 와닿으므로, [Int]가 syntatic sugar이라고 할 수 있다. Array에서의 Type Annotation> as를 쓰면 된다.let arrayOfUInt8s: [UInt8] = [2, 4, 7] // type annotation on the variablelet arrayOfUInt8s = [2, 4, 7] as [UInt8] // type annotation on the initializer expressionlet arrayOfUInt8s = [2 as UInt8, 4, 7] // explicit for o..
Section 5.2: Booleans and Inline Conditionals (불리언과 삼항연산자)Boolean 값을 가지는 인자 value를 함수 내부에서 삼항연산자로 받아서 이것을 String안에 나타내는~func isTurtle(_ value: Bool) { let color = value ? "green" : "red" print("The animal is \(color)")}isTurtle(true) // outputs 'The animal is green'isTurtle(false) // outputs 'The animal is red' Section 5.3: Boolean Logical OperatorsOR ( || ), AND ( && ), XOR ( ^ )XOR 연산자는 두 ope..
Reversing Strings 문자열 거꾸로 하는 방법: .characters.reversed() 를 쓴다.let aString = "This is a test string."let reversedCharacters = aString.characters.reversed() String contains Characters from a Defined Set특정 문자열 안에서 캐릭터 찾기let letters = CharacterSet.letterslet phrase = "Test case"let range = phrase.rangeOfCharacter(from: letters)// range will be nil if no letters is foundif let test = range { print(..
구현 방법1. data source를 반영해서 보여주는 UITableView에서 테이블 뷰 셀을 만든다.2. UITableViewDelegate의 scrollViewDidScroll 메서드를 가지고와서, 유저가 테이블 뷰의 제일 하단으로 스크롤을 했을 때 감지할 수 있도록 한다.3. 유저가 테이블뷰의 제일 하단에 닿았을 때, 데이터를 더 가지고 와서 현존하는 data source에 추가해서 더한다.4. reloadData 로 새로운 데이터를 가져온 테이블뷰를 업데이트해서 디스플레이한다. code snippetfunc scrollViewDidScroll(_ scrollView: UIScrollView) { let offsetY = scrollView.contentOffset.y let conte..

키 바인딩에 들어가서 'markdown'을 검색한다.나의 경우 단축키를 옵션+R로 설정을 해놨고, 이건 플레이그라운드에서만 된다!
간혹가다 API 결과값에 태그가 있는 경우가 있다. 그럴 때는 Regex로 없애주면 되는데, 문제점은 제목 구분자로 이런 식으로 쓴 것들은 다 날아간다. extension String { var stripHTML: String { return self.replacingOccurrences(of: "]+>", with: "", options: .regularExpression) } func stripOutHtml() -> String? { do { guard let data = self.data(using: .unicode) else { return nil } let at..

지난 포스팅:2024.09.06 - [앱 개발/iOS] - KakaoAPI를 활용한 BookSearch 앱 만들기 (1) KakaoAPI를 활용한 BookSearch 앱 만들기 (1)Kakao API를 통해, 책 검색 API를 사용해 검색한 키워드대로 책 목록을 가져오고, 목록을 클릭하면 상세 화면으로 넘어가 책에 대한 상세 내용을 웹뷰로 띄워줄것이다. func search()먼저 Kakao API로 책wildguess.tistory.com 저번 포스팅과 같이 코드를 작성하면 시뮬레이터에 위와 같은 화면밖에 보이지 않는다. 그 이유는 Delegate 를 해주는 tableView에게, 데이터를 호출해서 재가공한 시점에서 새로 생성했다고 알려줘야한다.그러나 아래와 같이 reloadData()를 하면 에러..

Kakao API를 통해, 책 검색 API를 사용해 검색한 키워드대로 책 목록을 가져오고, 목록을 클릭하면 상세 화면으로 넘어가 책에 대한 상세 내용을 웹뷰로 띄워줄것이다. func search()먼저 Kakao API로 책을 검색할 수 있는 함수를 만들어줄 것이다. (API 활용부분은 넘어가기로 함.)func search() 안에 url, request를 구현해준다.func search(){ var endPoint = "https://dapi.kakao.com/v3/search/book?sort=recency&query=love" guard let url = URL(string: endPoint) else { return } var request = URLReque..