• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: @property and @synthesize not working
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: @property and @synthesize not working


  • Subject: Re: @property and @synthesize not working
  • From: Nathan Gilmore <email@hidden>
  • Date: Wed, 13 Aug 2008 22:27:46 -0400

Hi Andrew,

Thanks so much for your quick response and all of the great tips!

You were right.  dayOneTasks was nil.

I am a little confused about how this works with Interface Builder. In MainMenu.nib, I have a DayOneTasks Controller. It's class is set to DayTaskController.

I also have the outlet for AppController.dayOneTasks set to the DayOneTasks Controller Object in the nib file. So, I guess by doing that, AppController.dayOneTasks still does not get initialized unless I call the alloc and init methods?

Thank you,
Nathan

On Aug 13, 2008, at 9:55 PM, Andrew Merenbach wrote:

On Aug 13, 2008, at 6:47 PM, Nathan Gilmore wrote:

Hello everyone,

I am a newbie and I am having trouble getting my setter to work when I use @synthesize. Here is the code:

**Header File**

@interface DayTaskController : NSArrayController {

	NSCalendarDate *searchDate;

}
- (void)search:(id)sender;

@property(readwrite, assign) NSCalendarDate *searchDate;

@end

**Implementation File**
@implementation DayTaskController

@synthesize searchDate;
@synthesize appController;
.
.
.

**AppController**
I try and just set the searchdate field and then output it:

- (id) init
{
	[super init];

	[self setDayOneDate:[NSCalendarDate calendarDate]];
	NSLog(@"self dayOneDate = %@",dayOneDate);
	[dayOneTasks setSearchDate:dayOneDate];
	NSLog(@"dayOneTasks search date = %@", [dayOneTasks searchDate]);
	return self;
}

The above code gives this output:
2008-08-13 21:30:23.081 LifeTask2[20085:10b] self dayOneDate = 2008-08-13 21:30:23 -0400
2008-08-13 21:30:23.082 LifeTask2[20085:10b] dayOneTasks search date = (null)


Any suggestions as to what I am doing wrong?

Thank you!
Nathan


Hi, Nathan!

Have you checked to ensure that dayOneTasks itself is not nil? Also, are you using Garbage Collection? If *not*, then try changing from "assign" to "retain" in your property declaration.

Also, a couple of suggestions: be sure to write your first line as "self = [super init];" (instead of "[super init];" by itself). Additionally, you may wish to consider using the standard property syntax, such as:

dayOneTasks.searchDate = dayOneDate;

NSLog(@"dayOneTasks search date = %@", dayOneTasks.searchDate);


-- instead of using the bracketed accessors. That's one reason, in my opinion, that properties are a good idea -- they can simplify syntax and/or improve readability for certain cases.

Cheers,
	Andrew

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: @property and @synthesize not working
      • From: "Michael Ash" <email@hidden>
    • Re: @property and @synthesize not working
      • From: Andrew Merenbach <email@hidden>
References: 
 >@property and @synthesize not working (From: Nathan Gilmore <email@hidden>)
 >Re: @property and @synthesize not working (From: Andrew Merenbach <email@hidden>)

  • Prev by Date: Re: Allowing menu item selection in a modal session
  • Next by Date: Does NSNotificationCenter have zeroing weak references to observers ?
  • Previous by thread: Re: @property and @synthesize not working
  • Next by thread: Re: @property and @synthesize not working
  • Index(es):
    • Date
    • Thread