본문 바로가기

iOS

(16)
iOS - UINavigationController + UISearchController + UISearchBarDelegate 안녕하세요, 오늘은 저희가 자주사용하는 서치바를 Navigation Item에 추가하는 실습을 해 보겠습니다. 일단 기본적으로 UISearchController 객체를 생성해 줘야 겠죠. 아래와 같은 코드로 생성해 줍니다. let searchController = UISearchController(searchResultsController: nil) 그리고 이제 서치컨트롤러를 navigation controller에 대입해 줘야 하는데요, navigation item이 가지고 있는 searchController 속성을 사용해서 assign 해 줍니다. navigationItem.searchController = searchController 이제 delegate pattern 구현을 위해 UISearch..
iOS - Alamofire Alamofire: URLRequest와 URLSession을 사용하기 편리하도록 만들어 놓은 라이브러리1. 설치: cocoapods를 이용해서 Alamofire설치. 2. 요청(request)만들기 (하나의 메소드로 끝냄.) :Alamofire.request(url:URL, method: 요청방식, parameters: [String:String], encoding: 인코딩방식설정, headers:Header) 헤더에 추가하고 싶은게 있다면 headers에 추가. open API를 찾았는데, 문서에 query(파라미터임). -h 에 있는 부분을 header에 넣음. 예: 인증키(developers.kakao.com에서 검색 api 참고) => method: get, post등 => parameters:..
iOS - UIImageView를 활용한 Animation 구현 안녕하세요, 오늘은 UIImageView 를 활용하여 iOS에서 Animation 효과를 구현해 보고자 합니다. 정적 매소드로 UIView의 animate 메소드나 transition animations를 주로 사용하는데요, UIKit은 UIImageView를 여러개 활용하여 애니메이션을 생성하는 API 역시 제공합니다. 오늘은 그 방법을 구현해 보겠습니다. 일단 UIImageView 는 애니메이션 활용을 위해 아래와 같은 속성과 메소드들을 제공합니다. var animationImages: [UIImage]? var highlightedAnimationImages: [UIImage]? var animationDuration: TimeInterval var animationRepeatCount: Int f..
iOS - IBOutlet & IBAction On a Interface builder, hold down the control button and drag & drop to your UIViewController. Then, you will see @IBOulet and @IBAction. When you name your IBAction, try to describe the fact that it was tapped or it pressed. ex: buttonPressed. You can see InterfaceBuilder file on your left and Swift file on your right. Be sure to memorize the following two APIs as they are very useful when you ..
iOS - TableView Dynamic Cell Good morning all, I would like to write about table view's dynamic cell today. When you make memo app or to-do app, you might want to sell the entire details of your memo on the memo list. In this case, you could consider write the following codes; import UIKit // Custom Cell Class. I always recommend you to create the UITableViewCell class in a seperate file. class CustomCell: UITableViewCell {..
Source Control with Xcode Today, I would like to write about source control using xcode. In order to use github, you need check "Create Git Repository on my Mac", when you create your xcode project,. Otherwise, local repository will not be installed. Now put some labels or images on your storyboard. Once you have done that, make your second commit. First commit is automatically done when you initiated your project. Move ..
iOS - Defer문 Defer문: 코드에 실행싯점을 Scope가 종료되는 때로 지연시킴. Syntax defer { statements } defer문을 호출하면 블록에 포함된 코드가 바로 실행되지는 않고, defer문이 호출된 스코프에 실행이 종료될 때까지 연기됨. defer문 활용: Defer문에 실행은 함수가 종료될때까지 연기. 런타임오류가 발생하서 프로그램이 비정상적으로 종료되는 경우를 제외하고, 항상 함수가 종료되는 싯점에 실행됨. 특별한 이유가 없다면 하나의 defer문만 사용하는 것이 좋음.
iOS - Closure 최적화 Closures최적화 - Github에는 많은 사람들이 자신의 iOS앱 코드를 Public으로 올려놓아서 저희가 참고로 활용할 수 있는데요, 그런데 많은 코드들을 보면 아래와 같이 $0, $1, $2... 표시로 된 클로저 형태를 발견 할 수 있습니다. 저도 처음 접했을 때는 저게 클로저라는 걸 몰랐었는데요, 클로저 최적화를 적용한 코드는 많은 개발자들이 사용하기 때문에 꼭 알아두어야 한다고 생각합니다. 예: products.filter { $0.contains(“Pro”) } 그럼 클로저 최적화를 위한 5가지 규칙을 알아 봅시다. 1. 파라미터 형식과 리턴형을 생략한다. - 컴파일러가 자동으로 클로저의 반환타입을 정의. 컴파일러가 구문내의 반환값을 찾아 해당하는 타입으로 전환. - 파라미터의 타입은 컴..