2012-10-27 2 views
2

으로 초기화 나는 세트는 NSSet를 전달하고 주요 기능의 값

NSMutableSet *set1 = [[NSMutableSet alloc ]init]; 
    NSMutableSet *set2 = [[NSMutableSet alloc ]init]; 

을하고 난 어떤 값으로 "초기화"할 수있는 기능을 갖고 싶어.

처럼 (하지만 작동하지) :

void initSet (NSMutableSet *set1, NSMutableSet *set2) 
{ 
    NSArray *a1 = [NSArray arrayWithObjects: intNum(1), intNum(2), nil]; 
    NSArray *a2 = [NSArray arrayWithObjects:intNum(3), intNum(4), intNum(5), intNum(6), intNum(7), nil]; 

    set1 = [NSMutableSet setWithArray: a1]; 
    set2 = [NSMutableSet setWithArray: a2]; 
} 

답변

0

세트들은 포인터에 대한 포인터로 전달 될 필요가있다. 일반 포인터가 값에 의해 전달되는 경우 set1set2을 수정해도 호출자가 initSet으로 전달한 값은 변경되지 않습니다.

void initSet (NSMutableSet **set1, NSMutableSet **set2) 
{ 
    NSArray *a1 = [NSArray arrayWithObjects: intNum(1), intNum(2), nil]; 
    NSArray *a2 = [NSArray arrayWithObjects:intNum(3), intNum(4), intNum(5), intNum(6), intNum(7), nil]; 

    *set1 = [NSMutableSet setWithArray: a1]; 
    *set2 = [NSMutableSet setWithArray: a2]; 
} 

콜이 기능은 다음과 같이

NSMutableSet *s1, *s2; 
initSet(&s1, &s2);