3

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 :)

Lou Franco
  • 83,503
  • 14
  • 127
  • 183

3 Answers3

2

@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.

Lou Franco
  • 83,503
  • 14
  • 127
  • 183
1

@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.

Community
  • 1
  • 1
NRitH
  • 11,597
  • 4
  • 36
  • 40
0

Header files are there for the compiler to know what you can call on a given class, what arguments are there, etc. They are also useful for people to get a sense of what the public interface of a class is.

They do not have implementations though. iOS ships with headers public so you can see them, but you cannot see the implementation of these methods.

If you can expand your question to be more specific on what you're trying to understand, I might be able to provide you more assistance.

Ben Scheirman
  • 39,034
  • 20
  • 96
  • 135