이 코드는 무엇을 의미합니까?"isKindOfClass"란 무엇이며 왜 사용합니까?
[images isKindOfClass:[NSArray class]]
부울을 반환하지만 왜 사용합니까? 객체가 주어진 클래스를 상속 (또는이다) 때
감사
이 코드는 무엇을 의미합니까?"isKindOfClass"란 무엇이며 왜 사용합니까?
[images isKindOfClass:[NSArray class]]
부울을 반환하지만 왜 사용합니까? 객체가 주어진 클래스를 상속 (또는이다) 때
감사
isKindOfClass
true를 반환합니다. 이 경우 images
이 NSArray
또는 NSArray
의 하위 클래스인지 확인합니다.
내가 작업중인 코드의 사용 예는 iPad ([ctrl isKindOfClass:[BaseSplitViewController class]]
) 또는 iPhone 용으로 표시해야하는 항목을 처리해야하는지 확인하는 것입니다. 이와 같이 :
CGRect backViewFrame = CGRectZero;
if ([currentController isKindOfClass:[BaseSplitViewController class]]) {
//Set width and hight of background View to 1024.
[backgroundView setFrame:CGRectMake(0, 0, 1024, 1024)];
if (UIInterfaceOrientationIsLandscape(orientation)) {
backViewFrame = CGRectMake(0, 0, 1024, 768);
} else if (UIInterfaceOrientationIsPortrait(orientation)) {
backViewFrame = CGRectMake(0, 0, 768, 1024);
}
} else {
backViewFrame = currentController.view.frame;
[backgroundView setFrame:backViewFrame];
}
왜 이것을 사용하고 싶습니까? –
또한 동일한 클래스인지 확인하고 상속 할 수 있습니다. – rmaddy
@rmaddy는 그것을 분명히했다. – thegrinner
설명서를 읽으세요? http://developer.apple.com/library/ios/#documentation/cocoa/reference/foundation/Protocols/NSObject_Protocol/Reference/NSObject.html – lifetimes
질문을하기 전에 문서를 읽어보십시오. – rmaddy
당신이 제공하는 간단한 예제에서는별로 도움이되지 않을지 모르지만, 다른 유형의 객체가 반환되는 상황 (예 : NSArray 또는 NSDictionary를 반환 할 수있는 JSON을 파싱하는 경우)에 매우 유용합니다. 반환되었습니다). – Rob