0

I am new to objective-c. My object reportingTime is nil in init method. What I am doing wrong ? How can I initialize reportingTime and set firstweekday ?

I have the following interface and implementation

My interface file Calculation.h

@interface Calculate : NSObject {

NSCalendar *reportingTime;
....
....
}
@property NSCalendar *reportingTime;

@end

And my implementation file Calculate.m

#import "Calculate.h"

@implementation Calculate

@synthesize reportingTime;

- (id)init
{
    if(self = [super init]) {
        reportingTime = [[NSCalendar alloc] init];
        [reportingTime setFirstWeekday:1];

        // reportingTime is nil ??????
    }
    return self;
}
0

2 Answers 2

1

Use

- (id)initWithCalendarIdentifier:(NSString *)string

instead of standart init method. See more: https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSCalendar_Class/Reference/NSCalendar.html

Sign up to request clarification or add additional context in comments.

1 Comment

And why is #import "Calculate.m" in Calculate.m?
0

Instead of

reportingTime = [[NSCalendar alloc] init];

use:

reportingTime = [[NSCalendar currentCalendar] retain];

The retain because this is a direct assignment to the @property ivar and [NSCalendar currentCalendar] is a convenience method that returns an autoreleased var. If you are using ARC the retain is not necessary.

1 Comment

it was a typo it is Calculate I have changed it but still not working

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.