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
1
vote
1 answer

Why make an IBOutlet variable an ivar (not a property)?

I've been perusing an open source project that uses a storyboard that contains a few view controllers. For some reason, the UI elements do not use @property IBOutlet declarations in the .h file, but rather are ivar's (sometimes __weak) declared in…
1
vote
3 answers

Using a C array as a property

I need to declare a property for a C array of a custom struct type. Can someone explain what I should be doing with this C array as far as property declarations? Should I not be using a property declaration at all? I tried memset()ing the memory in…
Joey
  • 7,537
  • 12
  • 52
  • 104
1
vote
1 answer

Safe mutation and usage of readonly property value in Objective-C APIs

Consider a C++ API like const T* foo(). This clearly documents the supported mutability and use of the API: OK, we'll let you look at T, but please don't change it. You can still mutate it, but you have to explicitly use const_cast to indicate your…
user5709700
1
vote
2 answers

Is declaring strong actually needed for Objective-C properties?

My understanding so far is that (retain) increases the reference count of a property and is essentially the exact same as (strong). Since all properties are set to retain by default (unless specified otherwise), is adding (strong) needed at…
user1686342
  • 1,265
  • 1
  • 18
  • 24
1
vote
1 answer

Error using NSMutableString property "Attempt to mutate immutable object with appendString:"

When I to append a string to an NSMutableString using appendString: I get the following error: Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Attempt to mutate immutable object with appendString:' My code…
Jaap Wijnen
  • 417
  • 2
  • 6
  • 12
1
vote
1 answer

Are declared property attributes overridden when implementing custom accessor methods?

Suppose I declare a property like so @property (nonatomic, copy) NSObject *property; Then I create a custom setter method - (void) setProperty:(NSObject *)property { _property = property; // Some more code here } Does the compiler…
jeremywhuff
  • 2,911
  • 3
  • 29
  • 33
1
vote
1 answer

Identifying properties in the header file vs. implementation file

I have been interested in using something along the the lines of the following code to automate the building of my objects (since there are many of them with quite a few properties): MyObject *myObject = [[myObject alloc] init]; unsigned int…
1
vote
2 answers

Override a property to make it read-only from the subclass

I would like to subclass UILabel in such a way that the user of the class cannot set the text directly through label.text = @"foo". Instead I'd like to set the text from inside the subclass depending on some values. What I…
1
vote
1 answer

Autoit GUI, Variables not being declared on button press

I am still in the process of learning how to script my own GUIs. Koda has been a big help, I have been messing around with it, learning little bits at a time. However, I have encountered an error that I can not seem to get around. The current GUI I…
MHFSU
  • 55
  • 8
1
vote
1 answer

Enforcing copy semantics for users of my Objective-C class

I have an Objective-C class that's intended for copy semantics. @property (copy) ViewState* viewState; It’s not immutable, but everything that hangs on to a ViewState instance needs its own distinct copy. In fact, if some other class mistakenly…
Mark Bernstein
  • 2,090
  • 18
  • 23
1
vote
3 answers

Inverting a BOOL property without using dot syntax

In this line of code I am reversing a BOOL value: someObject.boolValue = ![someObject boolValue]; How can I rewrite this line in "pure" Objective-C syntax, without dot syntax?
Olex
  • 1,656
  • 3
  • 20
  • 38
1
vote
2 answers

Why the setter is called for one property but not the other?

I took this code from the Big Nerd Ranch iOS Programming book. In the code, they are assigning two instance variables, coordinate and title. Why is coordinate assigned directly, and title is set by calling a setter? Header File @interface…
felix
  • 11,304
  • 13
  • 69
  • 95
0
votes
3 answers

C++, recieve this when trying to create classes: error: no ‘void media::*()’ member function declared in class ‘media’

Somewhat new to c++, attempting to create classes/functions to make my future code clean. I am using Code::Blocks to create my program and at the moment receiving the above message for the following cpp and header files for disctype, ripmusic and…
bjsawlor
  • 1
  • 1
0
votes
1 answer

Error: Could not find any functions to execute for transaction

my issue is that I am defining transaction in model file and then using it in js script but it throws an error " Error: Could not find any functions to execute for transaction." when i try to execute.It occurs during testing of the code my mode…
0
votes
1 answer

Implicit conversion of an Objective-C pointer to 'int *' is disallowed with ARC after move property to .h file

I have a controller which has properties defined like this in .m file: @interface ContentViewController () @property (nonatomic, strong) SwipeView *swipeView; @property (nonatomic, strong) NSMutableArray…
armnotstrong
  • 8,605
  • 16
  • 65
  • 130