레이블이 xcode인 게시물을 표시합니다. 모든 게시물 표시
레이블이 xcode인 게시물을 표시합니다. 모든 게시물 표시

2020년 4월 16일 목요일

Objective C로 만들어진 프로젝트에서 swift 사용하기

기존에 Objective C로 구현되어 있는 App 에 신규 기능을 추가 해야 하는데 swift로 하고 싶으면?


1. Xcode Project -> Target -> Build Settings -> Defines Modules 'Yes'
   Xcode Project -> Target -> Build Settings -> Swift Language Version 5







2. Swift Code 추가

3. Objective C 에서 swift 함수를 사용할 경우 @objc func , 프로퍼티를 참조 할 경우 @objc var

4. Swift에서 기존 Objective C 모듈에 연동이 필요한 경우
   프로젝트이름-Bridging-Header.h 에 #import 추가

이 과정을 거치고 나면 objective c / swift를 함께 이용할 수 있다.
ojbective c 에서 swift 로 만든 ViewController를 이용하고 swift로 만든 ViewController에서 기존 objective c 모듈에 기능을 이용 할 수 있다.




2019년 5월 4일 토요일

Xcode Server 를 이용한 CI (Continuous Integration)

Xcode Sever 를 이용한 CI (Continuous Integration)


Xcode로 개발 하면서 bitbucket에 있는 repository에 프로젝트를 자동으로 내려 받아 빌드 하고 테스트 하는 CI를 설정 하고 사용 하는 방법을 기록으로 남겨 본다.

Xcode 서버 활성


Xcode 서버를 활성 시키려면
Xcode -> Preference -> Server & Bots















스위치를 켜기만 하면 끝이다.

이제 Account로 가서 Xcode Server를 추가 한다.




Bot 설정


이제 비트 버킷으로 관리 되는 프로젝트를 클론 하여 Xcode로  열어 본다.

cocoapod 을 이용하여 xcworkspace로 열려진 프로젝트의 경우
.xcworkspace는 git으로 관리 하지 않는 상황에서 Xcode Server가 스스로 pod install 및 .xcworkspace를 로드 하여 프로젝트를 빌드 하고 테스트 하는 방법을 기술 한다.

bitbucket으로 클론 하면 xcworkspace가 존재 하지 않는다.
.xcworkspace는 git으로 add 하지 않고 관리 하지 않기 때문이다.

# pod install을 수행한다.
# open projectname.xcworkspace 로 워크스페이스를 연다.

워크스페이스로 열고 Xcode bot을 설정 하는 이유는 단지 bitbucket 의 url을 자동으로 열기 위함이었다.

상관 없다.

Product->Create Bot 으로 봇을 생성 한다.













워크스페이스를 연 이유는 자동으로 bitbucket  설정 을 위해서 였다.







CI 스케줄을 정한다. 매시간 이 디폴트이다.




테스트를 하는 시뮬레이터 및 디바이스를 선택 하는 단계 모든 디바이스와 모든 시뮬레이터를 설정 할 경우 Xcode Server가 빌드하고 테스트 하는동안 수많은 시뮬레이터 와 CPU 점유을 맥머신에 이륙 소리를 만날 것이다. 특정된 모델만 선택 하는 것을 강추 한다.







인증 서 단계등을 완료 하고 나면 봇이 생성 된다.

봇이 완료되면 바로 integration을 수행하는데 100% 실패 한다.

이유는 cocoa pod 프로젝트 그리고 .xcworkspace를 bitbucket에 pull 하지 않았기 때문에 빌드 과정에서 에러가 발생 한다.  projectname.xcworkspace 파일이 없기 때문에 실패 하는 것이다.




상단에 Edit bot을 클릭 한다.
맨 오른쪽 Trigger를 선택 한다.
하단 + 버튼을 클릭 하여

pre-integration script를 생성 한다.

#!/bin/sh
cd "${XCS_PRIMARY_REPO_DIR}/projectname"
pwd
/usr/local/bin/pod install

위와 같은 스크립트를 생성한다.

Xcode Server bot 이 프로젝트를 클론 해온다음
스크립트가 pod install을 수행하여 모든 pod 라이브러리를 내려 받아 놓고
생성된 .xcworkspace를 로드하여 빌드 및 테스트를 진행 한다.

unit test, ui test를 프로젝트에 등록 해두었으면 자동으로 빌드 및 테스트 까지 수행 하여 Xcode bot이 리포팅 해준다.

2018년 12월 14일 금요일

XCTest 에서 비동기 통신 class를 테스트를 하려면?

https://developer.apple.com/documentation/xctest/asynchronous_tests_and_expectations/testing_asynchronous_operations_with_expectations


위 링크를 보면 좋은 예제가 있다.


만일 네트워크 RESTFul API를 요청 하는 함수들 과
응답에 결과를 delegate로 호출 해주는 방법으로 만든 클래스가 있다면

이 class의 unit 테스트를 만들려면 testcase 함수 에서는 응답이 오기전에 XCAssertEqual()등의 메서드를 호출 할 수 없다. 네트워크 응답을 delegate로 받고 테스트가 진행 되어야 한다.


XCTest case 함수에서
XCTestExpectation 변수를 전역 변수로 만들고

테스트 케이스 함수에서 네트워크 요청 후
wait(for: [expectation], timeout: 10.0)
위와 같은 코드로 대기를 하게 한다.

XCAssertEqual() 메서드든 wait 코드 아래에 위치 하게 한다.

네트워크 클래스의 delegate 응답 결과를 처리 하는 protocol 메서드에서
expectation.fulfill() 을 호출 하여 대기를 풀어 준다.

그럼 wait이 풀리고 XCAssertEqual에서 테스트 판단이 이루어진다.

말로 설명한 TestCase 코드는 다음과 같다.

let expectation = XCTestExpectation(description: "Network API TEST")
    func testLogin() {
        // 1. given

        // 2. when
        network.login = Network.Login(aId: "choijh", aPassword: "1234567a")
        network.request(API: Network.API.Login, delegate: self)

        wait(for: [expectation], timeout: 10.0)

        // 3. then
        XCTAssertEqual( self.success, true, "Login success")
    }
    
    func testLoginFail() {
        // 1. given
        
        // 2. when
        network.login = Network.Login(aId: "choijh", aPassword: "a")
        network.request(API: Network.API.Login, delegate: self)
        
        wait(for: [expectation], timeout: 10.0)
        
        // 3. then
        XCTAssertEqual( self.success, false, "Login fail wrong password")

    }
    
    func onReceiveSuccessFail(_ success: Bool, api: Network.API) {
        self.success = success
        expectation.fulfill()

    }

2018년 10월 7일 일요일

Xcode에서 이미지 없이 둥근 버튼, 원 버튼 디자인 적용 하기

1. 다음과 같은 라운드 버튼을 이미지 없이





zeplin 오른쪽 사이드에 사각형 이라 표시되고 전혀 image asset에 대한 정보가 없다.
디자이너는 그냥 파란색 도형을 디자인 한것이다.

로그인 버튼은 사각형이며 파란색 도형인데 이미지가 없다?

이러한 경우는

UIVew를 상속 받은 UIButton에서 conerRadius를 설정 하여 처리 하면 된다.
결국 코딩으로 해야 한다.


2. 이번에는 속이 투명한 완전 원형 버튼






width / height 값이 동일하게 그리고 conerRadius를 width/2 로 설정 하면 원이 된다.
결국 코딩이다.

viewDidLoad에 코딩으로 하지 않고 스토리보드 인터페이스 빌더에서 속성으로 처리 하고 싶다면?


import UIKit

extension UIView {
    
    @IBInspectable var cornerRadius: CGFloat {
        get {
            return layer.cornerRadius
        }
        set {
            layer.cornerRadius = newValue
            layer.masksToBounds = newValue > 0
        }
    }
    
    @IBInspectable var borderWidth: CGFloat {
        get {
            return layer.borderWidth
        }
        set {
            layer.borderWidth = newValue
        }
    }
    
    @IBInspectable var borderColor: UIColor? {
        get {
            return UIColor(cgColor: layer.borderColor!)
        }
        set {
            layer.borderColor = newValue?.cgColor
        }
    }

}


위와 같이 extension을 작성 하면

@IBInspectable 덕에 IB에 표시된다.



extension은 @IBDesignable이 적용이 되지 않아 storyboard 랜더링은 그대로 사각형이지만 런타임에서는 훌륭한 타원으로 표출 된다.


2번 원 버튼의 경우 배경색을 투명으로 하고 border with  와 border color 를 적용 하고 corner radius를 width에 1/2로 적용 하면 원 버튼이 표현 가능 하다.





















Xcode storyboard 리팩토링

Main.storyboard에 ViewController를 계속해서 디자인 하다 보면
성능이 별로 좋지 않은 mac에서는 랜더링 속도가 현저하게 떨어진다.

ViewController에 image등을 올리는 작업이 늘어 나면 늘어 날 수록 더이상 편집 자체가
너무 느려 하기 어려워 질 수도 있다.


이렇게 하나의 Main.storyboard에 모든 ViewController를 때려 박지 않고
여러개의 storyboard 파일로 나누어 segue를 연결 할 수 있다.


스토리보드 리팩토링 방법

1. 새로운 스토리 보드 파일을 추가 한다.
2. 기존 Main.storyboard 파일과 새로 만든 스토리 보드 파일을 보기 좋게 그룹으로 생성 하여 추가 한다.
3. Main.storyboard 파일에서 일부 연결된 ViewController들을 선택 하여 Cmd + X로 자른다.
4. 새로 추가된 스토리 보드 파일에 붙여 넣기를 한다.
5. 새로 추가된 스토리 보드에 첫번째 ViewController를 is Initial View Controller로 체크 한다.
6. Main.storyboard 파일에서 새로 추가된 스토리 보드와 segue를 연결 한다.





Main.storyboard를 간단하게 바꾸고 segue에 연결은 스토리 보드 레퍼런스로 한다.


Xcode 10에서는 라이브러리 화면이 팝업으로 나오게 되어 있다. Cmd + Shift + L




두번째 항목이 스토리 보드 레퍼런스 이다.

이런한 과정을 통해 프로젝트 성격에 맡도록 storyboard 파일을 나누면
각각의 스토리 보드에서 적은수의 View Controller를 처리 하도록 하여 Xcode에서 보다 쾌적 하게 작업 할 수 있다.

2018년 9월 20일 목요일

iOS ViewController 그라데이션 배경색 적용 하기


위와 같이 zeplin에서 색상 정보가 표시되고 ViewController의 배경색을 적용 해야 하는 경우

디자이너님에게 배경 PNG를 주세요! 라고 할 수도 있고
코드로 해결 할 수도 있다.

위 두점은 그라데이션의 시작점이다.
그리고 두개의 색상 정보가 있다.

extension CAGradientLayer {
    
    convenience init(frame: CGRect, colors: [UIColor]) {
        self.init()
        self.frame = frame
        self.colors = []
        for color in colors {
            self.colors?.append(color.cgColor)
        }
        startPoint = CGPoint(x: 0, y: 0)
        endPoint = CGPoint(x: 1, y: 1)
    }
    
    convenience init(frame: CGRect, colors: [UIColor], startPoint: CGPoint, endPoint: CGPoint) {
        self.init()
        self.frame = frame
        self.colors = []
        for color in colors {
            self.colors?.append(color.cgColor)
        }
        self.startPoint = startPoint
        self.endPoint = endPoint
    }
    
    func createGradientImage() -> UIImage? {
        
        var image: UIImage? = nil
        UIGraphicsBeginImageContext(bounds.size)
        if let context = UIGraphicsGetCurrentContext() {
            render(in: context)
            image = UIGraphicsGetImageFromCurrentImageContext()
        }
        UIGraphicsEndImageContext()
        return image
    }

}

위코드에서 첫번째 convenience 초기화는 대각선 즉 0,0 ~ 1,1 로 그라데이션 을 적용 하는 것이고
추가로 두번째 convenience초기화는 startPoint와 endPoint를 파라메터로 전달 할 수 있도록 만든 초기화 이다.


위와 같이 extension을 만들고

실제 ViewController에서 imageView를 전체 영역으로 올리고 다음과 같이 코딩을 한다.

    @IBOutlet weak var backgroundImage: UIImageView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

        
        var colors = [UIColor]()
        colors.append( colorLiteral(red: 0, green: 0.6941176471, blue: 1, alpha: 1))
        colors.append( colorLiteral(red: 0.05882352941, green: 0.8392156863, blue: 0.8078431373, alpha: 1))
        let gradientLayer = CAGradientLayer(frame: self.view.frame, colors: colors, startPoint: CGPoint(x: 0.5, y:0), endPoint: CGPoint(x:0.5, y:1))
        backgroundImage.image = gradientLayer.createGradientImage()


    }


colorLiteral을 사용해서 숫자로 표시되지만 실제로른 Xcode에서 색상 표를 이용해 hex로 입력 한것이다.


CGPoint(x: 0.5, y:0)  ~ CGPoint(x:0.5, y:1) 은 중앙 상단에서 중앙 하단을 의미 한다.













2018년 4월 18일 수요일

Xcode 9 에서 컬러 리터럴 사용하기

코드에서 색상 값을 UIColor()에 생성자에 RGB 값으로 코딩을 하면 무슨 색인지 코드만 보고는 알수가 없다.



Xcode에서는 이러한 점을 고려하여 위와 같이 color literal을 지원하게 되었다.
색상이 Xcode에디터에서 문자 처럼 표시 된다.

color lteral을 코드에 적용 하는 방법은 다음과 같다.

color literal을 타이핑 하면 다음과 같이 코드 완성이 이루어지려 한다.


에디터에서 색상을 더블클릭 하면 색상 선택 창이 나타난다.




Other를 선택 하여 RGB 및 alpha 값을 적용 하여 원하는 색상 리터럴 문자를 만들수 있다.




이렇게 코드를 작성하면 실제는 colorLiteral() 로 코딩되어 있고 Xcode editor 상에서는 색상으로 표시되어 가독성이 좋다.











2018년 4월 12일 목요일

Xcode 9 에서 markdown파일을 렌더링 하여 보기




Xcode에서 .md 파일을 추가 할수 있다.
하지만 기본은 그냥 편집 할 수 있게만 되고 미리보기라 든지 그런 기능이 없다.


위에글은 링크된 파일을 다운로드 받으면 Xcode 프로젝트가 있는데 Xcode로 오픈해 보면 정말 README.md 가 렌더링 되서 보여준다.

아무런 차이도 없는데 해당 프로젝트는 그렇게 보여준다.
위 리크에서 설명 하듯이 답은 .xcodesamplecode.plist 파일이 프로젝트 (패키지 내용보기) 내부 에 있는 것이다. 파인더에서도 디폴트는 보여지지 않기 때문에 터미널을 이용하여 ls -al 로 확인 하였다.

sparrow-mac-mini:ARKitExample.xcodeproj sparrow$ ls -al
total 56
drwxr-xr-x@ 6 sparrow  staff    204  4 12 22:18 .
drwxr-xr-x@ 9 sparrow  staff    306  4 12 22:03 ..
-rw-r--r--@ 1 sparrow  staff    182  8  8  2017 .xcodesamplecode.plist
-rw-r--r--  1 sparrow  staff  24272  4 12 22:07 project.pbxproj
drwxr-xr-x@ 5 sparrow  staff    170  4 12 22:04 project.xcworkspace
drwxr-xr-x  3 sparrow  staff    102  4 12 22:04 xcuserdata

현재 작업중인  프로젝트는 워크스페이스로 구성되어 있었는데 여러 포함된  프로젝트 파일중에 README.md 파일을 추가 했고 렌더링 된 결과가 나올 줄 알았지만 결과는 아무런 변화가 없다.

하여 잘못된 글로 생각 했다.

워크스페이스로 된 프로젝트에서는 .xcodesamplecode.plist 파일을 workspace 디렉토리에 넣어야 된다.

결국 이글은 정확하게 잘된다.

구지 ARKitExample.xcodeproj을 다운 받지 않고도

터미널에서 워크스페이스 파일이나 xcode 프로젝트 파일에 디렉토리에 들어가서 .xcodesamplecode.plist 파일을 생성 하면 될 것으로 보인다.

해당 파일의 냉용은 다음과 같다.

sparrow-mac-mini:ARKitExample.xcodeproj sparrow$ cat .xcodesamplecode.plist 
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array/>
</plist>


이파일이 프로젝트 디렉토리 (패키지내용보기) 또는 터미널에서 cd  진입 하여 .xcodesamplecode.plist (ARKitExample.xcodeproj) 에 있는 파일이나 직접 만들어 넣으면 xcode가 markdown 파일을 렌더링 해서 보여준다.

단! 렌더링 되면 수정 xcode에서는 수정이 되지 않는다.

Visual Studio Code로 편집 수정하여 Xcode 프로젝트에 추가하면 멋진 도큐먼트를 포함하는 프로젝트가 될 것이다.

그리고 표문법은 적용 되지 않는다.

그래도 이정도면 쓸만 하다.

2018년 3월 8일 목요일

가로 모드에서 특정 뷰가 전체 화면이 되는 앱을 autolayout으로 어떻게 구현 하는가?

세로 모드에서 컨텐츠가 가운데 표시되고 상단과 하단에는 네비게이션 바 부터 정보를 보여주는 Label 하단에는 각종 버튼이 있다고 하자.

이러한 상태에서 가로모드로 전환을 하면 가운데 컨텐츠가 전체 화면으로 변경 되는 앱을 만든다고 하면 어찌 하는가?
아래 그림을 참조






화면 전환을 인지 하는 코드는. willTransition() 메서드로 인지 할 수 있다.

UIDevice.current.orientation.isLandscape 의 값을 확인 하여 현재 landscape 모드인지 확인이 가능 하다.

이럴때 가운데 컨텐츠의 autolayout constraint 값을 (0)으로 변경 하면 쉽게 해결 할 수 있다.
즉 세로모드로 IB에서 디자인을 하고 autolayout constraint를 적용 할때 Video 라는 글이 있는 검정색 뷰의 부모 뷰에 대한 constraint Align top to:와 Align Bottom to:를 IBOutlet으로 연결하여
코드로 값을 조정 하면된다.

나머지 나비게이션콘트롤러의 바나, 레이블, 버튼등도 코드로 isHidden 값을 정해 주면 된다.

하여 완성된  ViewController의 코드는 다음과 같다.

import UIKit

class ViewController: UIViewController {

    @IBOutlet weak var topContraint: NSLayoutConstraint!
    @IBOutlet weak var bottomConstraint: NSLayoutConstraint!
    @IBOutlet weak var infoLabel: UILabel!
    @IBOutlet weak var controlButton: UIButton!
    
    override func willTransition(to newCollection: UITraitCollection, with coordinator: UIViewControllerTransitionCoordinator) {
        if UIDevice.current.orientation.isLandscape == true {
            topContraint.constant = 0
            bottomConstraint.constant = 0
            self.navigationController?.isNavigationBarHidden = true
            infoLabel.isHidden = true
            controlButton.isHidden = true
        } else {
            topContraint.constant = 122
            bottomConstraint.constant = 300
            self.navigationController?.isNavigationBarHidden = false
            infoLabel.isHidden = false
            controlButton.isHidden = false
        }
    }


}

2018년 3월 1일 목요일

Xcode 9 GitHub 계정 지원 기능 알아 보기

xcode 9 이 되면서 Github 계정 연동 기능이 추가 되었다.
기존 버젼도 git을 지원 하기는 하였지만 좀더 많은 기능이 추가되었다.



특히 이번 버젼에는 좌측 Navigator 화면에 Source Control Navigator가 추가 되었고 직관적으로 볼수 있게 되었다.

1. github계정 생성



메뉴 Xcode -> Preferences -> Accounts
에서 Github 계정을 추가 할 수 있다.





메뉴 Xcode -> Preferences -> Source Control -> Git
에서 git 관련 설정을 할 수 있다.


2. Source Control Navigator 활용





좌측 Source Control Navigator ( Cmd + 2) 화면에서는 브랜치 전환 및 git message를 확인 할 수 있는 기능이 새롭게 추가 되었다.


3. github 계정에 원격 리포지토리 생성





Source Control Navigator에서. Remotes 마우스 우클릭으로 원격 리포지토리 생성이 가능 하다. 계정 설정에 연결된 GitHub 계정에 원격 리포지토리를 생성 할 수 있다.








branch 생성 branch 간 전환도 가능 하다.

4. 머지



test브랜치를 만들고 브랜치 전환을 하여 수정한 다음 손쉽게 마스터 브랜치에 머지 할 수 있다.


6. 소스 컨트롤 메뉴



상단 메뉴에서 Source Control 메뉴 GitHub 프로젝트에 대한 Clone , Repositores 생성 , Commit, Push, Pull 등 모든 기능을 할 수 있는 메뉴가 존재 한다.



이상으로 간단하게 Xcode 9 에 새롭게 추가된 github 연동 및 git 관련 기능을 살펴 보았다.


2018년 2월 8일 목요일

Xcode codesnippets 여러 맥머신에서 동일하게 동기화 하기 with iCloud version

https://mtsparrow.blogspot.kr/2016/01/xcode-code-snippets-key-binding-font.html

이미 드랍박스를 이용하여 코드 스니핏을 동기화 한적이 있다.

폰트, 단축키도 동기화 가능 하다.


이번에는 같은 방법으로 iCloud 드라이브를 이용하는 것으로 동일한 방법이다.

아이클라우드 도큐먼트 디렉토리에 XcodeDocs를 생성 한다.

$ mkdir ~/Library/Mobile\ Documents/com~apple~CloudDocs/Documents/XcodeDocs

Xcode의 코드 스니프 디렉토리를 아이클라우드 디렉토리에 이동 한다.
$ mv -v ~/Library/Developer/Xcode/UserData/CodeSnippets ~/Library/Mobile\ Documents/com~apple~CloudDocs/Documents/XcodeDocs/

링크를 걸어준다. 다른 머신도 아래와 같이 링크를 걸어 주면 된다.
$ ln -s ~/Library/Mobile\ Documents/com~apple~CloudDocs/Documents/XcodeDocs/CodeSnippets/ ~/Library/Developer/Xcode/UserData/CodeSnippets






2017년 3월 8일 수요일

Xcode 8.2.1 application building시 크래쉬 발생

Exception Type:        EXC_CRASH (SIGABRT)
Exception Codes:       0x0000000000000000, 0x0000000000000000
Exception Note:        EXC_CORPSE_NOTIFY

Application Specific Information:
ProductBuildVersion: 8C1002
UNCAUGHT EXCEPTION (NSRangeException): *** -[__NSArrayM objectAtIndex:]: index 3 beyond bounds [0 .. 2]
UserInfo: (null)
Hints: 
  0: Creation Backtrace for Notification Token:

  0   -[_DVTNotificationReceiver initWithBlock:queue:] (in DVTFoundation)
  1   -[NSNotificationCenter(DVTNSNotificationCenterAdditions) dvt_addObserverForName:object:queue:usingBlock:] (in DVTFoundation)
  2   -[_IDENavigatorOutlineViewDataSource setRootItems:] (in IDEKit)
  3   -[IDENavigatorOutlineView _updateRootItems:sortDescriptors:] (in IDEKit)
  4   -[IDENavigatorOutlineView setRootItems:] (in IDEKit)
  5   -[IDENavigatorOutlineView _updateBoundContentArrayOrSet] (in IDEKit)
  6   -[IDENavigatorOutlineView updateBoundContentArray] (in IDEKit)
  7   -[NSObject(DVTBindingUtilities) updateBoundValueForBinding:] (in DVTKit)
  8   -[DVTBindingHelper observeValueForKeyPath:ofObject:change:context:] (in DVTKit)
  9   NSKeyValueNotifyObserver (in Foundation)
 10   NSKeyValueDidChange (in Foundation)
 11   -[NSObject(NSKeyValueObservingPrivate) _changeValueForKey:key:key:usingBlock:] (in Foundation)
 12   _NSSetObjectValueAndNotify (in Foundation)
 13   -[IDEBatchFindNavigator updateScopeItems:] (in IDEKit)
 14   __44-[IDEBatchFindNavigator setupLocationPicker]_block_invoke_2 (in IDEKit)
 15   -[NSObject(DVTObservingConvenience) _dvt_newObserverForKeyPath:options:owner:creationBacktrace:withHandlerBlock:] (in DVTFoundation)
 16   -[NSObject(DVTObservingConvenience) dvt_newObserverForKeyPath:options:withHandlerBlock:] (in DVTFoundation)
 17   -[IDEBatchFindNavigator setupLocationPicker] (in IDEKit)
 18   -[IDEBatchFindNavigator viewDidInstall] (in IDEKit)
 19   -[DVTViewController _viewDidInstall] (in DVTKit)
 20   -[_DVTViewController_ViewLifecycleInterpositions viewDidMoveToWindow] (in DVTKit)
 21   -[NSView _setWindow:] (in AppKit)
 22   -[NSView addSubview:] (in AppKit)
 23   __42-[DVTReplacementView _setupViewController]_block_invoke (in DVTKit)
 24   DVTInvokeWithFailureHint (in DVTFoundation)
 25   -[DVTReplacementView _setupViewController] (in DVTKit)
 26   -[DVTReplacementView installedViewController] (in DVTKit)
 27   -[DVTReplacementView layoutTopDown] (in DVTKit)
 28   -[DVTLayoutView_ML _reallyLayoutIfNeededTopDown] (in DVTKit)
 29   +[DVTLayoutView_ML _doRecursivelyLayoutSubviewsOfView:populatingSetWithLaidOutViews:completionCallBackHandlers:currentLayoutPass:needsSecondPass:] (in DVTKit)
 30   +[DVTLayoutView_ML _doRecursivelyLayoutSubviewsOfView:populatingSetWithLaidOutViews:completionCallBackHandlers:currentLayoutPass:needsSecondPass:] (in DVTKit)
 31   +[DVTLayoutView_ML _doRecursivelyLayoutSubviewsOfView:populatingSetWithLaidOutViews:completionCallBackHandlers:currentLayoutPass:needsSecondPass:] (in DVTKit)
 32   +[DVTLayoutView_ML _doRecursivelyLayoutSubviewsOfView:populatingSetWithLaidOutViews:completionCallBackHandlers:currentLayoutPass:needsSecondPass:] (in DVTKit)
 33   +[DVTLayoutView_ML _doRecursivelyLayoutSubviewsOfView:populatingSetWithLaidOutViews:completionCallBackHandlers:currentLayoutPass:needsSecondPass:] (in DVTKit)
 34   +[DVTLayoutView_ML _doRecursivelyLayoutSubviewsOfView:populatingSetWithLaidOutViews:completionCallBackHandlers:currentLayoutPass:needsSecondPass:] (in DVTKit)
 35   +[DVTLayoutView_ML _recursivelyLayoutSubviewsOfView:populatingSetWithLaidOutViews:] (in DVTKit)
 36   -[DVTLayoutView_ML viewWillDraw] (in DVTKit)
 37   -[NSView viewWillDraw] (in AppKit)
 38   -[NSView viewWillDraw] (in AppKit)
 39   -[NSView viewWillDraw] (in AppKit)
 40   -[NSView _sendViewWillDrawInRect:clipRootView:] (in AppKit)
 41   -[NSView displayIfNeeded] (in AppKit)
 42   -[NSWindow displayIfNeeded] (in AppKit)
 43   ___NSWindowGetDisplayCycleObserver_block_invoke6365 (in AppKit)
 44   __37+[NSDisplayCycle currentDisplayCycle]_block_invoke (in AppKit)
 45   CA::Transaction::run_commit_handlers(CATransactionPhase) (in QuartzCore)
 46   CA::Context::commit_transaction(CA::Transaction*) (in QuartzCore)
 47   CA::Transaction::commit() (in QuartzCore)
 48   CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) (in QuartzCore)
 49   __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ (in CoreFoundation)
 50   __CFRunLoopDoObservers (in CoreFoundation)
 51   CFRunLoopRunSpecific (in CoreFoundation)
 52   RunCurrentEventLoopInMode (in HIToolbox)
 53   ReceiveNextEventCommon (in HIToolbox)
 54   _BlockUntilNextEventMatchingListInModeWithFilter (in HIToolbox)
 55   _DPSNextEvent (in AppKit)
 56   -[NSApplication _nextEventMatchingEventMask:untilDate:inMode:dequeue:] (in AppKit)
 57   -[DVTApplication nextEventMatchingMask:untilDate:inMode:dequeue:] (in DVTKit)
 58   -[NSApplication run] (in AppKit)
 59   NSApplicationMain (in AppKit)
 60   start (in libdyld.dylib)

Backtrace:
  0   __exceptionPreprocess (in CoreFoundation)
  1   DVTFailureHintExceptionPreprocessor (in DVTFoundation)
  2   objc_exception_throw (in libobjc.A.dylib)
  3   -[__NSArrayM objectAtIndex:] (in CoreFoundation)
  4   -[_IDENavigatorOutlineViewDataSource outlineView:child:ofItem:] (in IDEKit)
  5   refreshRowEntryItemAndLevelInfo (in AppKit)
  6   -[NSOutlineView reloadItem:reloadChildren:] (in AppKit)
  7   -[IDENavigatorOutlineView reloadItem:reloadChildren:] (in IDEKit)
  8   __83-[_IDENavigatorOutlineViewDataSource _processNavigableItemGraphChangeNotification:]_block_invoke.735 (in IDEKit)
  9   +[NSAnimationContext(DVTNSAnimationContextAdditions) dvt_nonAnimatedBlock:] (in DVTKit)
 10   -[IDENavigatorOutlineView suspendEditingWhilePerformingBlock:] (in IDEKit)
 11   -[_IDENavigatorOutlineViewDataSource _processNavigableItemGraphChangeNotification:] (in IDEKit)
 12   DVTInvokeWithLazyFailureHint (in DVTFoundation)
 13   __48-[_DVTNotificationReceiver receiveNotification:]_block_invoke.42 (in DVTFoundation)
 14   -[_DVTNotificationReceiver receiveNotification:] (in DVTFoundation)
 15   __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ (in CoreFoundation)
 16   ___CFXRegistrationPost_block_invoke (in CoreFoundation)
 17   _CFXRegistrationPost (in CoreFoundation)
 18   ___CFXNotificationPost_block_invoke (in CoreFoundation)
 19   -[_CFXNotificationRegistrar find:object:observer:enumerator:] (in CoreFoundation)
 20   _CFXNotificationPost (in CoreFoundation)
 21   -[NSNotificationCenter postNotificationName:object:userInfo:] (in Foundation)
 22   -[NSNotificationCenter(DVTNSNotificationCenterAdditions) _dvt_postNotificationName:object:userInfo:] (in DVTFoundation)
 23   -[IDENavigableItemCoordinator _postNotificationNamed:forChangedItems:] (in IDEKit)
 24   -[IDENavigableItemCoordinator _delayedPostGraphAndPropertyChangeNotifications] (in IDEKit)
 25   __48-[DVTDelayedInvocation initWithTarget:selector:]_block_invoke (in DVTFoundation)
 26   -[DVTDelayedInvocation runBlock:] (in DVTFoundation)
 27   __NSFirePerformWithOrder (in Foundation)
 28   __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ (in CoreFoundation)
 29   __CFRunLoopDoObservers (in CoreFoundation)
 30   __CFRunLoopRun (in CoreFoundation)
 31   CFRunLoopRunSpecific (in CoreFoundation)
 32   RunCurrentEventLoopInMode (in HIToolbox)
 33   ReceiveNextEventCommon (in HIToolbox)
 34   _BlockUntilNextEventMatchingListInModeWithFilter (in HIToolbox)
 35   _DPSNextEvent (in AppKit)
 36   -[NSApplication _nextEventMatchingEventMask:untilDate:inMode:dequeue:] (in AppKit)
 37   -[DVTApplication nextEventMatchingMask:untilDate:inMode:dequeue:] (in DVTKit)
 38   -[NSApplication run] (in AppKit)
 39   NSApplicationMain (in AppKit)
 40   start (in libdyld.dylib)

abort() called

Application Specific Signatures:
NSRangeException

Application Specific Backtrace 1:
0   CoreFoundation                      0x00007fff9993a452 __exceptionPreprocess + 178
1   DVTFoundation                       0x0000000106127762 DVTFailureHintExceptionPreprocessor + 194
2   libobjc.A.dylib                     0x00007fff882b8f7e objc_exception_throw + 48
3   CoreFoundation                      0x00007fff99851725 -[__NSArrayM objectAtIndex:] + 245
4   IDEKit                              0x000000010776c830 -[_IDENavigatorOutlineViewDataSource outlineView:child:ofItem:] + 190
5   AppKit                              0x00007fff86d092e5 refreshRowEntryItemAndLevelInfo + 327
6   AppKit                              0x00007fff86d02f67 -[NSOutlineView reloadItem:reloadChildren:] + 3024
7   IDEKit                              0x0000000107767d7b -[IDENavigatorOutlineView reloadItem:reloadChildren:] + 357
8   IDEKit                              0x000000010776ac2e __83-[_IDENavigatorOutlineViewDataSource _processNavigableItemGraphChangeNotification:]_block_invoke.735 + 522
9   DVTKit                              0x000000010685464f +[NSAnimationContext(DVTNSAnimationContextAdditions) dvt_nonAnimatedBlock:] + 132
10  IDEKit                              0x0000000107765441 -[IDENavigatorOutlineView suspendEditingWhilePerformingBlock:] + 101
11  IDEKit                              0x000000010776a76d -[_IDENavigatorOutlineViewDataSource _processNavigableItemGraphChangeNotification:] + 2226
12  DVTFoundation                       0x0000000106127576 DVTInvokeWithLazyFailureHint + 100
13  DVTFoundation                       0x00000001060e1f32 __48-[_DVTNotificationReceiver receiveNotification:]_block_invoke.42 + 149
14  DVTFoundation                       0x00000001060e1c7f -[_DVTNotificationReceiver receiveNotification:] + 1054
15  CoreFoundation                      0x00007fff998c5b1c __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 12
16  CoreFoundation                      0x00007fff998c5aaf ___CFXRegistrationPost_block_invoke + 63
17  CoreFoundation                      0x00007fff998c5a27 _CFXRegistrationPost + 407
18  CoreFoundation                      0x00007fff998c5792 ___CFXNotificationPost_block_invoke + 50
19  CoreFoundation                      0x00007fff99882542 -[_CFXNotificationRegistrar find:object:observer:enumerator:] + 1922
20  CoreFoundation                      0x00007fff99881795 _CFXNotificationPost + 693
21  Foundation                          0x00007fff9718e17a -[NSNotificationCenter postNotificationName:object:userInfo:] + 66
22  DVTFoundation                       0x00000001060e338a -[NSNotificationCenter(DVTNSNotificationCenterAdditions) _dvt_postNotificationName:object:userInfo:] + 360
23  IDEKit                              0x000000010794c00f -[IDENavigableItemCoordinator _postNotificationNamed:forChangedItems:] + 542
24  IDEKit                              0x000000010794c35d -[IDENavigableItemCoordinator _delayedPostGraphAndPropertyChangeNotifications] + 713
25  DVTFoundation                       0x0000000105ef15a8 __48-[DVTDelayedInvocation initWithTarget:selector:]_block_invoke + 79
26  DVTFoundation                       0x0000000105ef298b -[DVTDelayedInvocation runBlock:] + 257
27  Foundation                          0x00007fff9726884a __NSFirePerformWithOrder + 339
28  CoreFoundation                      0x00007fff998cefc7 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
29  CoreFoundation                      0x00007fff998cef37 __CFRunLoopDoObservers + 391
30  CoreFoundation                      0x00007fff998ae408 __CFRunLoopRun + 872
31  CoreFoundation                      0x00007fff998ade38 CFRunLoopRunSpecific + 296
32  HIToolbox                           0x00007fff87c2b935 RunCurrentEventLoopInMode + 235
33  HIToolbox                           0x00007fff87c2b76f ReceiveNextEventCommon + 432
34  HIToolbox                           0x00007fff87c2b5af _BlockUntilNextEventMatchingListInModeWithFilter + 71
35  AppKit                              0x00007fff869a2df6 _DPSNextEvent + 1067
36  AppKit                              0x00007fff869a2226 -[NSApplication _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 454
37  DVTKit                              0x00000001066d1eaf -[DVTApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 396
38  AppKit                              0x00007fff86996d80 -[NSApplication run] + 682
39  AppKit                              0x00007fff86960368 NSApplicationMain + 1176
40  libdyld.dylib                       0x00007fff94a015ad start + 1
41  ???                                 0x0000000000000001 0x0 + 1

위와 같은 콜스택을 뿜으며 빌 Xcode 서 앱을 빌드 하다가 크래쉬가 발생하면서 비정상 종료 하고 다시  Xcode를 실행 시키면 실행 바로 크래쉬 되어  Xcode 수행이 어려운 경우

이런 경우
rm -rf ~/Library/Developer/Xcode/DerivedData



위 명령을 수행하여 Xcode를 수행 가능 하게는 할 수 있으나
다시 빌드를 하면 또 비정상 종료 되는 경우가 있다.

이런 경우 해결 방법

1.  Product -> Scheme -> Manage Scheme 
에서 새로운 빌드 스킴을 만들고 이전 빌드 스킴 대신 사용해본다.

위와 같이 해도 크래쉬가 발생하면

Pod 로 서드 파티 라이브러리를 이용하고  .xcworkspace를 사용중이라면
다음의 절차를 수행 한다.

프로젝트. xcworkspace파일을 과감하게 삭제 하고
pod install 명령으로 새로 .xcworkspace를 생성 하여 xcode를 새로 생성된 xcworkspace
파일로 시작 하고 빌드 한다.

2016년 10월 26일 수요일

trobleshooting installation issue with CocoaPods

CocoaPods

http://mtsparrow.blogspot.kr/2016/03/cocoapod.html

github에서 좋은 오픈소스를 찾아 iOS프로젝트에 추가 하려고 하면
CocoaPods을 주로 사용 했다.

 프로젝트에 프레임워크를 추가 하기 좋긴 한대 가끔 이게 문제가 생기고
이유 없는 빌드 에러를 만들어 내면 남감 하다.

Xcode에서 이유없는 빌드 에러를 만나거나 오동작 할때는 가끔씩
rm -rf ~/Library/Developer/Xcode/DerivedData

여기를 정리 하곤 한다.

CocoaPods 도 무언가 오동작을 하거나 계속되는 이유없는 빌드 에러를 만날때 
해볼 만한 방법은

pod cache clean frameworkName1
pod cache clean frameworkName2
pod cache clean frameworkName3
pod cache clean frameworkName4
pod deintegrate || rm -rf Pods
pod install --verbose
rm -rf ~/Library/Developer/Xcode/DerivedData


요즘은 Carthage 를 많이 사용하는 것 같다.

하지만 아직 사용방법을 모른다.

나중에 새로운 프로젝트를 시작 할때는 참조 프레임워크를 Carthage로 추가 해봐야 겠다.