LET me lOg

  • HOME
  • #iOS
  • Medium

포인터형 CF Object를 NS Object로 bridge 하기

포인터형 CF Object를 NS Object로 bridge 하기

iOS 내부에는 NS Object와 함께 CF Object로 이루어진(based) framework가 존재합니다.
xcode 4 이후 ARC가 적용되면서 이 두 object간 값을 bridge하는 __bridge 전처리기가 사용되는데 이 두 object간의 변환 방법입니다.

CFTypeRef inTypeRef = (__bridge CFTypeRef)result;

OSStatus status = SecItemCopyMatching((__bridge CFDictionaryRef)baseInformation, &inTypeRef);

if (status == errSecSuccess) {

    result = (__bridge_transfer NSData *)inTypeRef;
    password = [[NSString alloc] initWithData:result encoding:NSUTF8StringEncoding];

    }

위 예제는 Security.framework를 이용하여 Keychain에 저장된 값을 가져오는 예제입니다.

SecItemCopyMatching(CFDictionaryRef query, CFTypeRef *result) 함수의 두 번째 인자는 포인트를 가지는 CFTypeRef인데
이 값을 NSData로 옮기는 과정에서 위에서 설명한 변환법을 볼 수 있습니다.

즉, __bridge_transfer (NS Object)CG Object를 이용하여 옮긴 것입니다.

 

공유:

  • 친구에게 전자우편으로 보내기 (새 창에서 열림)
  • 페이스북에 공유하려면 클릭하세요. (새 창에서 열림)
  • 구글 +1에서 공유하려면 클릭하세요 (새 창에서 열림)
  • 트위터로 공유하기 (새 창에서 열림)
  • LinkedIn으로 공유하기 (새 창에서 열림)
  • Tumblr로 공유하기 (새 창에서 열림)
  • Pinterest에서 공유하려면 클릭하세요 (새 창에서 열림)

관련

공유:

  • 친구에게 전자우편으로 보내기 (새 창에서 열림)
  • 페이스북에 공유하려면 클릭하세요. (새 창에서 열림)
  • 구글 +1에서 공유하려면 클릭하세요 (새 창에서 열림)
  • 트위터로 공유하기 (새 창에서 열림)
  • LinkedIn으로 공유하기 (새 창에서 열림)
  • Tumblr로 공유하기 (새 창에서 열림)
  • Pinterest에서 공유하려면 클릭하세요 (새 창에서 열림)

관련

  • Permalink
  • 2013-01-25
  • iOS Common, iOS Simple Tips

Leave a Comment - Cancel reply

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax

Twitter Feed
  • Oops, our Twitter feed is unavailable at the moment. - Follow us on Twitter!
태그
3D touch 2011 2012 ACAccount Apple Artwork backgroundImage beta CoreAnimation Customizing Facebook FTA H3 hack Hidden image Indicator iOS iOS4 iOS5 iOS5.1 iOS6 iOS7 iOS9 iPad iPhone kth naver Path2 QuadMenu Swift TechTalk Tips Twitter UI UIButton UINavigationBar UINavigationController UITabBarController UITextField y8k 국회의원 매국노 아임IN핫스팟 한미FTA
그 밖의 기능
  • 로그인
  • 글 RSS
  • 댓글 RSS
  • WordPress.org
  • yoonbong.kim@me.com
  • Github
  • Linkedin
  • Twitter
  • YoonBong Kim © 2015
loading 취소
글이 전송되지 않았습니다. 이메일 주소를 확인하세요!
이메일 확인에 실패했습니다. 다시 시도하세요
죄송합니다. 귀하의 블로그에서 이메일로 글을 공유할 수 없습니다.