Hey everyone,
I'm just messing around with the NSMutableArray function, and I'm trying to return the array count, but it keeps returning 0.
I've added in printf functions to make sure the addObject methods are actually ran, and they do (well the loop is run correctly, and I don't receive any warnings or errors.)
My code:
initialSetup.h
initialSetup.m
main.m
The console returns:
I have a feeling there is something wrong with the variables in my returnMapSize method.
If someone could give me a hint, I'd appreciate it.
I'm just messing around with the NSMutableArray function, and I'm trying to return the array count, but it keeps returning 0.
I've added in printf functions to make sure the addObject methods are actually ran, and they do (well the loop is run correctly, and I don't receive any warnings or errors.)
My code:
initialSetup.h
Code:
#import <Foundation/Foundation.h>
@interface initialSetup : NSObject
@property NSMutableArray *xMapSize, *yMapSize;
-(void)setupMapXSize: (int)x YSize: (int)y;
-(void)printMap;
-(void)returnMapSize;
@end
initialSetup.m
Code:
#import "initialSetup.h"
@implementation initialSetup
@synthesize xMapSize, yMapSize;
-(void)setupMapXSize: (int)x YSize: (int)y {
for (int I = 1; I <= x; I++)
[xMapSize addObject: [NSNumber numberWithInt: I]];
for (int O = 1; O <= y; O++)
[yMapSize addObject: [NSNumber numberWithInt: O]];
}
-(void)printMap {
// Hmmmmm..
}
-(void)returnMapSize {
unsigned long xSize = [xMapSize count],
ySize = [yMapSize count];
printf("(%lu, %lu)\n", xSize, ySize);
}
@end
main.m
Code:
#import <Foundation/Foundation.h>
#import "initialSetup.h"
int main(int argc, const char * argv[])
{
@autoreleasepool {
initialSetup *graphMap = [[initialSetup alloc] init];
[graphMap setupMapXSize: 10 YSize: 10];
[graphMap returnMapSize];
}
return 0;
}
The console returns:
Code:
(0, 0)
Program ended with exit code: 0
I have a feeling there is something wrong with the variables in my returnMapSize method.
If someone could give me a hint, I'd appreciate it.