What the difference between declaring an @property in .h or .m file
@property (nonatomic, readwrite, assign) BOOL notificationDidLaunch;
Is it to do with the scope of the variable?
Also in the .h file whats the difference between declaring a string with the brakets like so
@interface AppDelegate : NSObject < UIApplicationDelegate > {
NSString *hat;
}
and doing it outside of them like below
@property (nonatomic, strong) NSString *hat;
As Tiago says, putting an @property declaration inside a class extension in the .m (implementation) file, is a way to make the property private so only the class itself can access it. When declared in the .h (public interface file), it is visible to all code that imports that .h file. Keep in mind that @properties are really just a convenience for declaring and synthesizing accessor methods, and as with all methods in Objective-C, they’re never truly private. The best you get is a compiler warning that no public interface declares the method in question if you try to use a non-public method in another class.
For the second part of your question, this declares an instance variable (“ivar”) called myString:
While this declares a property called myString:
The difference between an instance variable and an @property is more significant than just saying that an ivar is accessible only by your class’s instances. Declaring an ivar adds a variable to a class’s structure in memory. In contrast, @properties declare/define methods on a class. By default, these methods set/get the value of an associated, and similarly named ivar, but that’s not a requirement, and it is perfectly acceptable and quite common to have methods for an @property that don’t access an ivar directly. Say for example a class that has a firstName and lastName properties backed by
_firstNameand_lastNameivars, along with a third, fullName property that simply concatenates the value returned by the firstName and lastName getter methods together (and/or splits a two part name in its set method).