简体   繁体   English

这个属性声明是什么意思?

[英]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 . 所以我正在学习一些Xcode,今天我在网上学习了一个教程,我遇到了使用属性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 :) 非常感谢提前帮助:)

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

@property(nullable,nonatomic,copy) : declaring a property . @property(nullable,nonatomic,copy) :声明property It is allowed to be nil ( nullable ). 它被允许nilnullable )。 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 . 它将具有与多线程有关的非原子语义 - 意味着,默认情况下,如果没有某些同步(不要担心这一点),它就不是线程安全的,并且当它被设置时,它将进行copy

NSDictionary<NSString *,id> * - the type of the property is a dictionary that maps strings to any object ( id ). NSDictionary<NSString *,id> * - 属性的类型是将字符串映射到任何对象( id )的字典。

titleTextAttributes - the name of the property titleTextAttributes - 属性的名称

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 NS_AVAILABLE_IOS(5_0) - 这是一个对代码没有任何作用的宏,但是让你知道它自iOS 5.0起就可用了

The docs for UI_APPEARANCE_SELECTOR say: UI_APPEARANCE_SELECTOR的文档说:

To participate in the appearance proxy API, tag your appearance property selectors in your header with UI_APPEARANCE_SELECTOR. 要参与外观代理API,请使用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. PropertyType可以是任何标准iOS类型:id,NSInteger,NSUInteger,CGFloat,CGPoint,CGSize,CGRect,UIEdgeInsets或UIOffset。 IntegerType must be either NSInteger or NSUInteger; IntegerType必须是NSInteger或NSUInteger; we will throw an exception if other types are used in the axes. 如果在轴中使用其他类型,我们将抛出异常。

@property : Declares an object property (aka an ivar or instance variable in other languages) @property :声明一个对象属性(也就是其他语言中的ivar或实例变量)

(nullable,nonatomic,copy) : Attributes of the property. (nullable,nonatomic,copy) :属性的属性。 nullable means that a nil value is allowed. nullable意味着允许nil值。 nonatomic indicates that it's not thread-safe. nonatomic表示它不是线程安全的。 .

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. copy告诉编译器将属性视为value类型而不是reference类型,因此将从调用者复制属性值。

NSDictionary<NSString *,id> *: Declares the property's type. NSDictionary<NSString *,id> *:声明属性的类型。 In this case, it's an NSDictionary with NSString * keys, and any object type for values. 在这种情况下,它是带有NSString *键的NSDictionary ,以及值的任何对象类型。

titleTextAttributes : Finally , the name of the property. titleTextAttributes最后 ,属性的名称。

NS_AVAILABLE_IOS(5_0) : A macro that indicates in which iOS version the property first became available. NS_AVAILABLE_IOS(5_0) :一个宏,指示属性首次可用的iOS版本。

UI_APPEARANCE_SELECTOR; : Applied to properties that can use an appearance proxy. :应用于可以使用外观代理的属性。

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. iOS附带公共标题,因此您可以看到它们,但您无法看到这些方法的实现。

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. 如果您可以扩展您的问题以更具体地了解您想要了解的内容,我可以为您提供更多帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM