2015-02-06 7 views
0

나는 다음과 같이 CGImage에서 vImage_CGImageFormat를 생성 스위프트에서 함수를 쓰고 있어요 :CGColorSpace에서 관리되지 않는 <CGColorSpace>를 어떻게 얻습니까?

vImage_CGImageFormat(
    bitsPerComponent: UInt32(CGImageGetBitsPerComponent(image)), 
    bitsPerPixel: UInt32(CGImageGetBitsPerPixel(image)), 
    colorSpace: CGImageGetColorSpace(image), 
    bitmapInfo: CGImageGetBitmapInfo(image), 
    version: UInt32(0), 
    decode: CGImageGetDecode(image), 
    renderingIntent: CGImageGetRenderingIntent(image)) 

이 그러나 컴파일되지 않습니다. CGImageGetColorSpace(image)CGColorSpace!을 반환하고 위의 생성자가 colorSpace 매개 변수에만 Unmanaged<CGColorSpace>을 가져 가기 때문입니다.

다른 방법이 있습니까? 아마도 CGColorSpaceUnmanaged<CGColorSpace>으로 변환 하시겠습니까?

답변

2

이 작동합니다 :

vImage_CGImageFormat(
    // ... 
    colorSpace: Unmanaged.passUnretained(CGImageGetColorSpace(image)), 
    //... 
) 

struct Unmanaged<T> API 문서에서 :

/// Create an unmanaged reference without performing an unbalanced 
/// retain. 
/// 
/// This is useful when passing a reference to an API which Swift 
/// does not know the ownership rules for, but you know that the 
/// API expects you to pass the object at +0. 
/// 
/// :: 
/// 
/// CFArraySetValueAtIndex(.passUnretained(array), i, 
///       .passUnretained(object)) 
static func passUnretained(value: T) -> Unmanaged<T> 

업데이트 스위프트 3 :

vImage_CGImageFormat(
    // ... 
    colorSpace: Unmanaged.passUnretained(image.colorSpace!), 
    //... 
) 
+0

당신의 선생님을하는 gentleme 있습니다 n 학자 – fyell