Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does this property declaration mean?

So I am learning some Xcode and today I was following a tutorial online and I came across using the property titleTextWithAttributes.

I was looking at the header file and I cannot read this piece of code. Directly from the file. Note that I do not want to understand how to use it but rather I am trying to understand how it's defined.

/* You may specify the font, text color, and shadow properties for the title in the text attributes dictionary, using the keys found in NSAttributedString.h.
 */
@property(nullable,nonatomic,copy) NSDictionary<NSString *,id> *titleTextAttributes NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;

Thanks a lot in advance for the help :)


2 Answers

@property(nullable,nonatomic,copy) NSDictionary<NSString *,id> *titleTextAttributes NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;

@property(nullable,nonatomic,copy): declaring a property. It is allowed to be nil (nullable). It will have non-atomic semantics which has to do with multi-threading -- meaning, it is by-default not thread safe without some synchronization (don't worry about this) and when it is set, it will make a copy.

NSDictionary<NSString *,id> * - the type of the property is a dictionary that maps strings to any object (id).

titleTextAttributes - the name of the property

NS_AVAILABLE_IOS(5_0) - this is a macro that doesn't do anything for the code, but lets you know that it was available since iOS 5.0

The docs for UI_APPEARANCE_SELECTOR say:

To participate in the appearance proxy API, tag your appearance property selectors in your header with UI_APPEARANCE_SELECTOR.

Appearance property selectors must be of the form:

 - (void)setProperty:(PropertyType)property forAxis1:(IntegerType)axis1 axis2:(IntegerType)axis2 axisN:(IntegerType)axisN;
 - (PropertyType)propertyForAxis1:(IntegerType)axis1 axis2:(IntegerType)axis2 axisN:(IntegerType)axisN;

You may have no axes or as many as you like for any property. PropertyType may be any standard iOS type: id, NSInteger, NSUInteger, CGFloat, CGPoint, CGSize, CGRect, UIEdgeInsets or UIOffset. IntegerType must be either NSInteger or NSUInteger; we will throw an exception if other types are used in the axes.

like image 111
Lou Franco Avatar answered Nov 29 '25 23:11

Lou Franco


@property: Declares an object property (aka an ivar or instance variable in other languages)

(nullable,nonatomic,copy): Attributes of the property. nullable means that a nil value is allowed. nonatomic indicates that it's not thread-safe..

copy tells the compiler to treat the property as a value type, not a reference type, so the property value will be copied from the caller.

NSDictionary<NSString *,id> *: Declares the property's type. In this case, it's an NSDictionary with NSString * keys, and any object type for values.

titleTextAttributes: Finally, the name of the property.

NS_AVAILABLE_IOS(5_0): A macro that indicates in which iOS version the property first became available.

UI_APPEARANCE_SELECTOR;: Applied to properties that can use an appearance proxy.

like image 39
NRitH Avatar answered Nov 29 '25 23:11

NRitH



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!