Questions tagged [declared-property]

In Objective-C, declared properties are a convenient way to replace the declaration and manual implementation of accessor methods for objects.

A property declaration begins with the keyword @property. You can decorate a property with attributes by using the form @property(attribute [, attribute2, ...]).

You use the @synthesize directive to tell the compiler that it should synthesize the setter and/or getter methods for a property if you do not supply them within the @implementation block. The @synthesize directive also synthesizes an appropriate instance variable if it is not otherwise declared.

Declared properties provide a useful simplification of the usual requirement to explicitly declare all accessor methods, in the following ways (excerpt from Apple documentation on Declared Properties):

  • The property declaration provides a clear, explicit specification of how the accessor methods behave.
  • The compiler can synthesize accessor methods for you, according to the specification you provide in the declaration.
  • Properties are represented syntactically as identifiers and are scoped, so the compiler can detect use of undeclared properties.

Questions relating to the proper use of @property declarations, @synthesize, and the use of dot notation to assign values to these properties (object.propertyName = propertyValue;) should use this tag.

Further reading:

  1. The Objective-C Programming Language: Declared Properties
78 questions
0
votes
1 answer

Declare a static property in an Objective-C class interface

I'm defining an Objective-C class: @interface MyRequest : NSObject @property (strong, nonatomic, readonly) NSDecimalNumber *myNumber; @property (strong, nonatomic, readonly) CommConfig *commConfig; @property (nonatomic, assign, readonly) BOOL…
user1695758
  • 173
  • 1
  • 3
  • 14
0
votes
1 answer

Properties defined in category not found in original class

I have a very large class that I am trying to create a category from. In the original class' .m file, I have 2 objects (defined in the category .h file) that I'm getting "unidentified identifier" build errors. This is the object definition of one…
0
votes
1 answer

Why can I not use dot notation in "independent" blocks?

About Objective-c blocks, the document I am reading said: You can't refer to self in Independent block objects. if you need to, you must pass self object to the block as a parameter. You can't access to properties of an object inside an Independent…
0
votes
2 answers

When should I declare an instance variable rather than property in the header?

For example, in the following codes. @interface TUTViewController : UIViewController { NSTimer *timer; } @end and @interface TUTViewController : UIViewController @property (weak, nonatomic) NSTimer *timer; @end In which scenario do we use…
user3586299
  • 153
  • 1
  • 2
  • 10
0
votes
1 answer

Properties don't get initialized in iOS 7

I'm developing for iOS 7 but I still have to manually write getters otherwise my properties just don't get initialized. I tried to manually synthesize those properties, even though that shouldn't be needed anymore, but that doesn't do it. In my view…
0
votes
1 answer

Is the object retained when setting a property's ivar directly in -init?

My understanding is that instance variables should be accessed directly from inside the init method. For example: @interface ABC : NSObject @property (strong, nonatomic) NSString *name; @end @implementation ABC - (id)init { if ((self =…
0
votes
2 answers

Error "Property setVariableName not found" using dot notation to set property

I've just started learning Objective-C and I'm not sure when to use dot notation vs. square brackets. I know a similar question has been asked here but I'm still not really understanding the difference. I've read that [myObject doSomething] and…
Striving
  • 35
  • 8
0
votes
4 answers

Difference between using self.variable and _variable when init these variables

I know instance variable and property. I often see people init a UILabel like this self.label = [[UILabel alloc] init]; //and _label = [[UILabel alloc] init]; So, what's the difference between using self.label and _label to set a object?
yong ho
  • 3,892
  • 9
  • 40
  • 81
0
votes
4 answers

Does an object initialize automatically if it is the synthesized property of another object?

When you have one object as a property of another object in Objective-C, does it automatically initialize when you use @synthesize?
0
votes
2 answers

Set the properties of an NSObject from the values in an NSDictionary

I would like to know if it is possible to set the properties of an NSObject from an NSDictionary without setting each one individually. The property names in the NSObject match the key names in the NSDictionary. Is there an easy way of doing this?.…
Zigglzworth
  • 6,645
  • 9
  • 68
  • 107
0
votes
2 answers

Memory efficiency of three properties compared to one NSDictionary

I want to pass some data to my object and there are two options for me. Regarding memory - what's more effecient? To declare three properties or to to declare one NSDictionary using initWithCapacity:3?
alexhajdu
  • 410
  • 5
  • 13
0
votes
4 answers

Why are there only sometimes compiler errors when accessing a property without self?

I noticed that in some old versions of Xcode you could use properties of objects without self just fine. Now it gives me an error when I try to access my property without self, but today I'm writing this code, and it works fine, and doesn't give me…
Dvole
  • 5,725
  • 10
  • 54
  • 87
0
votes
2 answers

Does setting a property on a property call the first property's setter?

If a class has a custom setter for a property: @interface OuterClass : NSObject @property InnerClass *obj; -(void)setObj:(InnerClass *)obj; and InnerClass itself has a property: @property NSString *text; and I then do: obj.text = @"Hello"; will…
Joel Fischer
  • 6,521
  • 5
  • 35
  • 46
0
votes
1 answer

Why can't I access the auto-synthesized ivar?

I've been reading that with the lastest version of Xcode you don't even need to use synthesize to generate ivar, getters and setters, that Xcode itself handles this for you and creates something like _youIvarName for you, however after trying this…
0
votes
0 answers

Quick inquiry about ivars scope

Possible Duplicate: What is the visibility of @synthesized instance variables? What would the scopes (@private, @protected, etc.) of these ivars be? -@property/@synthesize -declared in .h -declared in .m
stumped
  • 3,235
  • 7
  • 43
  • 76