Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7998123
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:08:18+00:00 2026-06-04T15:08:18+00:00

i want initialize a nsdate with a specific date, to use it in all

  • 0

i want initialize a nsdate with a specific date, to use it in all my code an i’m doing this:

.h

@property (nonatomic, retain) NSDate *myDate;

.m

@synthesize myDate;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
        [formatter setDateFormat:@"yyyy-MM-dd"];

        myDate = [formatter dateFromString:@"2050-01-01"];
    } 
    return self;
}

then in the code, if i read that nsdate like in this way:

NSLog(@"%@",myDate);

or if i use isEqualToDate, give me a exc_bad_access

why?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T15:08:19+00:00Added an answer on June 4, 2026 at 3:08 pm

    In order to access the variable as a property, you need to invoke it as

    self.myDate = [formatter dateFromString:"2050-01-01"];
    

    Otherwise, it is just doing a straight assign to the variable storing it behind. When you declare a property as retain within the automatically generated setMyDate function that is invoked when you use self.myDate = someDate; a call to retain on the object passed in is made in order to hold onto the object.

    In general, it is considered a best practice to only access your properties through the automatically generated methods, or through self.myDate method to ensure proper use of reference counting functions

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to initialize all elements of: char buffer[1000][1000]; to ' ' . I've
I want to initialize libraries in cluster by their names represented as strings. This
I want to initialize a DateTime entity to the minimum possible date in TSQL.
I want to initialize a struct element, split in declaration and initialization. This is
I want to initialize var outside the foreach loop. Here is my code: public
i want to initialize a 2d array.. but my code doesn`t work, can somebody
I want to initialize a property of a class that holds a reference to
I want to initialize some lookup table in a shared library, I want to
I want to initialize an NSArray with numbers starting from 0,1,2,3... I know the
I want to initialize an array and then initialize a pointer to that array.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.