• 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
Understanding property/synthesize
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Understanding property/synthesize


  • Subject: Understanding property/synthesize
  • From: Stefan Nobis <email@hidden>
  • Date: Sat, 07 Aug 2010 17:52:28 +0200
  • Mail-followup-to: email@hidden

Hi.

I'm a bit curious about the Objective-C 2.0 property/synthesize
mechanism. In all examples I've seen, an instance variable is declared
for each property. But if I leave out the instance variable like in
the following example, everything works fine, too.

----------------------------------------------------------------------
#import <Foundation/Foundation.h>
#import <stdio.h>

@interface MyClass : NSObject
@property NSInteger number;
@end

@implementation MyClass : NSObject
@synthesize number;
@end

int main() {
  MyClass *obj = [[MyClass alloc] init];

  [obj setNumber: 77];
  printf("%d\n", (int)[obj number]);

  [obj release];
  return 0;
}
----------------------------------------------------------------------

So my question: What are the (possible) problems/implications if I
leave out the declarations of instance variable of properties? What
are the recommendations? More specific: Does the above also work/run
on iOS?

--
Until the next mail...,
Stefan.
_______________________________________________

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: Understanding property/synthesize
      • From: Quincey Morris <email@hidden>
  • Prev by Date: Re: NSFetchedResultsController from a certain object of a to-many relationship of an entity?
  • Next by Date: Problems with NSCell setObjectValue
  • Previous by thread: Re: NSFetchedResultsController from a certain object of a to-many relationship of an entity?
  • Next by thread: Re: Understanding property/synthesize
  • Index(es):
    • Date
    • Thread