Swift 3 개발 팁 모음

2017. 4. 2. 23:46아이폰 개발

* Swift 3 데이터 갱신 후, UI 업데이트 방법

http://stackoverflow.com/questions/37801370/how-do-i-dispatch-sync-dispatch-async-dispatch-after-etc-in-swift-3


* Swift 3 테이블뷰 이미지 다운로드 처리 방법

서드파티 라이브러리를 사용하지 않고 구현하는 방법

http://sweettutos.com/2015/12/31/swift-how-to-asynchronously-download-and-cache-images-without-relying-on-third-party-libraries/


* Swift 다른 뷰컨트롤러 실행하는 방법

http://stackoverflow.com/questions/38045161/switching-view-controllers-in-swift

let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("mainVC")
self.presentViewController(vc, animated: true, completion: nil)


* Swift 다른 뷰컨트롤러에 데이터 전달하는 방법

https://code.tutsplus.com/tutorials/ios-sdk-passing-data-between-controllers-in-swift--cms-27151


* TextField 입력 중일 때 처리하는 방법

func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
    if string == "" {
        // handle backspace scenario here
      return true
    } else if var textString = textField.text {
        let unitString = "kg"
        if textString.contains(unitString) {
            textString = textString.replacingOccurrences(of: unitString, with: "")
            textString += string + unitString
            textField.text = textString
        } else {
            textField.text = string + unitString
        }
        return false
    }
    return true
}

http://stackoverflow.com/questions/41582660/swift-3-append-to-uitextfield-while-editing-changed


* 이메일 주소 유효성 체크

http://swiftdeveloperblog.com/email-address-validation-in-swift/


* 키보드 상태에 따라 오토레이아웃 처리

https://blog.jaemyeong.com/2016/10/swift-3-ios-%ED%82%A4%EB%B3%B4%EB%93%9C-%EC%83%81%ED%83%9C%EC%97%90%EB%94%B0%EB%9D%BC-%EC%98%A4%ED%86%A0%EB%A0%88%EC%9D%B4%EC%95%84%EC%9B%83%EC%9D%84-%EC%82%AC%EC%9A%A9%ED%95%98%EC%97%AC-%EB%A0%88/

http://harrythegreat.tistory.com/entry/as-%ED%98%95%EB%B3%80%ED%99%98%EC%99%80-%ED%82%A4%EB%B3%B4%EB%93%9C-%EB%8B%AB%EA%B8%B0


* 카메라 연동 기능 구현

http://stackoverflow.com/questions/41750796/camera-ios-10-2-swift-3

https://swifter.kr/2016/10/19/swift-3-0%EC%97%90%EC%84%9C-%EC%B9%B4%EB%A9%94%EB%9D%BC-%EC%82%AC%EC%9A%A9%EC%9E%90%EC%A0%95%EC%9D%98-%EB%B0%A9%EB%B2%95/


* iOS 10 스케쥴 타이머 사용

http://stackoverflow.com/questions/38695802/timer-scheduledtimer-swift-3-pre-ios-10-compatibility


* Compress PNG Error 관련

http://stackoverflow.com/questions/2051947/how-can-i-skip-compressing-one-png


* 라운드 이미지 만들기

http://stackoverflow.com/questions/38954368/ios-swift-3-xcode8-beta-rounded-imageview


* 테이블뷰에서 제일 아래쪽으로 이동시키기

http://stackoverflow.com/questions/38886817/scroll-all-the-way-down-to-the-bottom-of-uitableview


* 임의의 색깔 지정하기

http://stackoverflow.com/questions/38558361/custom-color-swift


* 오디오 플레이시, 시간 정보 가져오기

http://stackoverflow.com/questions/37972759/how-to-make-slider-value-change-object-or-function


* How to parse JSON with Swift 3

http://roadfiresoftware.com/2016/12/how-to-parse-json-with-swift-3/

https://developer.apple.com/swift/blog/?id=37

http://stackoverflow.com/questions/40676847/sending-json-post-request-in-swift3


* HTTP Requests in Swift 3

http://stackoverflow.com/questions/38292793/http-requests-in-swift-3


* Swift Async Load Image

http://stackoverflow.com/questions/37018916/swift-async-load-image


* Swift 문자열 길이 구하는 법

http://stackoverflow.com/questions/39267428/how-do-i-get-the-length-of-a-string-in-swift3-on-macos

if purchaseDateString.characters.count == 0 {
     purchaseDateString = "n/a"
}


* Swift 문자열 Split 방법

http://stackoverflow.com/questions/25678373/swift-split-a-string-into-an-array

let fullName = "First Last"
var fullNameArr = fullName.components(separatedBy: " ")

var firstname = fullNameArr[0] // First
var lastname = fullNameArr[1] // Last


* URL 객체가 nil이 될 때

http://stackoverflow.com/questions/39539713/url-nil-after-upgrade-to-swift-3-0

if let correctedAddress = firstResult.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed),
    let url = URL(string: "https://maps.googleapis.com/maps/api/geocode/json?address=\(correctedAddress)") {
    print(url)
}


* NSUserDefaults (SharedPreferences) 사용 방법

https://advancetechtutorial.blogspot.kr/2016/08/using-nsuserdefaultssharedpreferences.html