2009-07-02 5 views
3

내 질문에 왜 로그의 마지막 4 줄을 출력합니까 (아래 참조) ... 해당 개체는 사전에 로그에 인쇄 된 사전의 일부입니다. & 배열의 끝에? 35 : 12.756 WhatATool [6407 : 10B]는 NSString
2009-07-02 09 : 35 : 12.756 WhatATool [6407 여기 근본적인 뭔가 ... 들으사전을 포함하는 열거 배열 예기치 않은 출력을 생성합니다

NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys: 
    [NSURL URLWithString: @"www.stanford.edu"], 
    @"Stanford University", 
    [NSURL URLWithString: @"www.apple.com"], 
    @"Apple shop", 
    [NSURL URLWithString: @"cs193p.stanford.edu"], 
    @"CS193P course", 
    [NSURL URLWithString: @"itunes.stanford.edu"], 
    @"Stanford on iTunes U", 
    [NSURL URLWithString: @"stanfordshop.com"], 
    @"Stanford Mall", 
    nil]; 

NSMutableArray *myArray = [NSMutableArray arrayWithObjects: 
    [NSString init], 
    [NSURL URLWithString: @"www.stanford.edu"], 
    [NSProcessInfo processInfo], 
    dictionary, 
    [@"Mutable string example" mutableCopy], 
    [@"another mutable string" mutableCopy]]; 

NSEnumerator *enumerator = [myArray objectEnumerator]; 
id object; 

while ((object = [enumerator nextObject])) { 
    NSLog([object description]); 
} 

2009-07-02 09 말이냐 : 10B] www.stanford.edu
2009-07-02 09 : 35 : 12.757 WhatATool [6407 : 10B] <NSProcessInfo: 0x107e20>
2009-07-02 09 : 35 : 12.758 WhatATool [6407 : 10B] {
"애플 shop "= www.apple.com;
"CS193P course"= cs193p.stanford.edu;
"Stanford Mall"= stanfordshop.com;
"Stanford University"= www.stanford.edu;
"iTunes U의 스탠포드"= itunes.stanford.edu;
}
2009-07-02 09 : 35 : 12.758 WhatATool [6407 : 10B] 변경 가능한 문자열 예
2009-07-02 09 : 35 : 12.759 WhatATool [6407 : 10B 다른 가변 문자열
2009-07 -02 09 : 35 : 12.760 WhatItool [6407 : 10b] itunes.stanford.edu
2009-07-02 09 : 35 : 12.760 iTunes의 스탠포드 U
2009-07-02 09:35 : 12.761 WhatATool [6407 : 10B] stanfordshop.com
2009-07-02 09 : 35 : 12.762 WhatATool [6407 : 10B] 스탠포드 몰

답변

24

난 당신이 마지막 인수로 필요한 전무를 놓치고 생각 할 때 편리한 메소드를 사용하여 NSMutableArray를 생성하십시오. 합니까

NSMutableArray *myArray = [NSMutableArray arrayWithObjects: 
    [NSString init], 
    [NSURL URLWithString: @"www.stanford.edu"], 
    [NSProcessInfo processInfo], 
    dictionary, 
    [@"Mutable string example" mutableCopy], 
    [@"another mutable string" mutableCopy], 
    nil]; 

작동합니까?

+0

덕분에 힙 스가 나를 놓치지 않을 것입니다. - 반가워요. –

4

경고를 켜고 (다른 경고 플래그 "-Wall") 당신은 얻을 것이다 :

경고 : NSMutableArray를 arrayWithObjects 방법의 끝에 함수 호출

에서 감시 누락이에 대해 당신에게 누락되었습니다.

+0

-Wall로 하루를 절약 할 수 있습니다. 그것은 종종 무시당하는 많은 분출물을 생산하지만 실제로 빛나는 때가 있습니다 ... –

+1

"분만의 톤"? 나는 - 벽으로 영구적으로 달리고 "경고를 오류로 취급한다."(빌드를 할 때 몰래 움직이고 다시 볼 수없는 경고를 피한다). 내 코드는 경고없이 깔끔하게 컴파일됩니다. 나는 당신이 문제가 될 수있는 진절머드 한 제 3 자 코드를 사용하여 붙들려는 것 같지만, 그 외의 경우에는 경고를 수정하십시오! –