0
두 개의 임의의 배열을 생성하고 유사한 숫자를 확인하기 위해 Objective C 프로그램을 만들고 있습니다. 표시된 코드 줄에 "NSRangeException"이 표시되지만 이유가 확실하지 않습니다. 내 코드는 다음과 같습니다."NSRangeException"오류, 확실하지 않은 이유
// Array Comparator (Check Two Arrays for Similar Numbers)
@interface ArrayComparator: NSObject
{
NSMutableArray *arrayOne;
NSMutableArray *arrayTwo;
}
- (void) generateFirstArray;
- (void) generateSecondArray;
- (void) check;
@end
@implementation ArrayComparator
- (void) generateFirstArray
{
arrayOne = [[NSMutableArray alloc] initWithCapacity: 50];
for (NSUInteger n = 0; n < 50; n++)
{
[arrayOne addObject: @(arc4random_uniform(999) + 1)];
}
for (NSUInteger n = 0; n < 50; n++)
{
printf("%li, ", (long) [arrayOne[n] integerValue]);
}
printf("first array.\n\n");
}
- (void) generateSecondArray
{
arrayTwo = [[NSMutableArray alloc] initWithCapacity: 50];
for (NSUInteger n = 0; n < 50; n++)
{
[arrayTwo addObject: @(arc4random_uniform(999) + 1)];
}
for (NSUInteger n = 0; n < 50; n++)
{
printf("%li, ", (long) [arrayTwo[n] integerValue]);
}
printf("second array.\n\n");
}
- (void) check
{
long similar = 0;
for (NSUInteger n = 0; n < 50; n++)
{
for (NSUInteger m = 0; m < 50; n++)
{
if ([arrayOne[n] integerValue] == [arrayTwo[m] integerValue]) // This is where I get the error.
{
similar++;
}
}
}
printf("There are %li similar numbers between the two arrays!", similar);
}
@end
int main(int argc, const char * argv[])
{
@autoreleasepool
{
ArrayComparator *arrayComp = [[ArrayComparator alloc] init];
[arrayComp generateFirstArray];
[arrayComp generateSecondArray];
[arrayComp check];
} return 0;
}
감사합니다. (나의 noobishness을 변명하십시오.)
감사합니다. 감사합니다. 나는 지금 바보 같아. XD – AmiableNebula