NSLOG does not work

144 views Asked by At

I try to get info for the array in the console but the NSLOg does not show anything. This is a class where i store data for the app. Here is the code.

#import <Foundation/Foundation.h>
#import "DAObject.h"

@interface DataModel : NSObject

@property (strong, nonatomic) NSArray *array;
@property (strong, nonatomic) NSArray *array2;

@end

and in the .m file

#import "DataModel.h"
@implementation DataModel

- (id)initWithCoder:(NSCoder *)decoder {
    if (self = [super init]) {               
    }
    return self;
}

- (NSArray *) _array
{
    DAObject *obj1 = [[DACityObject alloc] init];
    obj1.name = @"Obj1";

    DACityObject *obj2 = [[DACityObject alloc] init];
    obj2.name = @"Obj2";

    _array = @[ obj1, obj2];

    for (int i = 0; i < [_array count]; i++)
    {
        NSLog(@"Item %d = %@", i, [_array objectAtIndex:i]);
    }

    return _array;
}

- (NSArray *) array2 {    
    _array2 = [[NSArray alloc] initWithObjects:@"icon1.png", @"icon2.png",@"icon3.png",   nil];

    for (int i = 0; i < [_array2 count]; i++) {
        NSLog(@"Item %d = %@", i, [_array2 objectAtIndex:i]);
    }
    return _array2;
}

@end

Where is the problem? I can't figure it out.

1

There are 1 answers

2
l0gg3r On BEST ANSWER

You need to access from anywhere to that getters, after that you will see logs. For example try to do that in your AppDelegate.m

#import "DataModel.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    DataModel *data = [DataModel new];
    data.array;
    data.array2;
}