2012-06-10 2 views
1

내가 찾고 있어요 CFDictionaryCreateCFDictionaryCreate 아날로그 [NSDictionary에 dictionaryWithObject ...]

어떤 아이디어를 어떻게 구현하는 방법과 CoreFoundation에서 즉에 의해 사전

NSDictionary *frameProperties = [NSDictionary dictionaryWithObject:[NSDictionary 
                dictionaryWithObject:[NSNumber numberWithInt:2] 
                   forKey:(NSString *) kCGImagePropertyGIFDelayTime] 
            forKey:(NSString *) kCGImagePropertyGIFDictionary]; 

다음 만들 수있는 방법은?

+0

NSDictionary를 CFDictionary로 캐스트 할 수 없습니까? –

+0

물론, 내 질문에 대한 생각은 무엇입니까? 나는 순수 C++/C로 코딩하고있다. – deimus

+1

CF의 핵심이 NS ​​* 클래스를 사용하는 Objective-C에서 완전히 구현되었다고 가정하면, 왜 정확히 캐스트 할 수 없습니까? – bbum

답변

2

본인이 직접 답변을 구성한 것처럼 보입니다. 누군가를 확인하십시오. 코드가 정상적으로 컴파일되지만 아직 테스트 할 수 없습니다.

int delayOnEachFrame = 2; 
    const void *tkeys[1] = { kCGImagePropertyGIFDelayTime }; 
    const void *tvalues[1] = { CFNumberCreate(0, kCFNumberSInt32Type, &delayOnEachFrame) }; 
    CFDictionaryRef tframeProperties = CFDictionaryCreate(NULL, tkeys, tvalues, 1, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); 

    const void *keys[1] = { kCGImagePropertyGIFDictionary }; 
    const void *values[1] = { tframeProperties }; 
    CFDictionaryRef frameProperties = CFDictionaryCreate(NULL, keys, values, 1, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); 
+4

메모리 관리를 잊지는 않더라도 근본적으로 맞습니다. 'tvalues','tframeProperties', 그리고 결국'frameProperties'에서'CFNumber'를 해제해야합니다. 또한 하나의 키 - 값 쌍이있는 경우 실제 배열을 만들 필요가 없습니다. 외로운 변수를 만들고 포인터를 전달할 수 있습니다. –

+0

이봐, 이거 빨리 할 수 ​​있니? – san