In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article will explain in detail what common macros are about iOS. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.
FOUNDATION_EXPORT, UIKIT_EXTERN
The macro works like extern and works similarly to extern. In the .m file, the definition is as follows
NSString * const kFoundationExportString = @ "Hello World"; NSString * const kExternString = @ "Hello World"
You can then access the constant in the class that imported the .h file by adding the following declaration to the .h file.
FOUNDATION_EXPORT NSString * const kFoundationExportString; extern NSString * const kExternString
If you want to access these two constants in a class that does not import the .h file, you should put the above code in the .m file of the class.
UIKIT_EXTERN only adds compatibility compared to extern, using the same method.
The use is as follows:
NSString * str = @ "Hello World"; if (str = = kConstantString) {NSLog (@ "equal");}
String constants declared with FOUNDATION_EXPORT compare the address of the pointer, while constant strings defined by the # define macro can only be compared using isEqualToString, which is more efficient.
Comparison between define and FOUNDATION_EXPORT
NS_STRING_ENUM and NS_EXTENSIBLE_STRING_ENUM
These two macro definitions are used for bridging Swift for Objective-C, and their purpose is to enumerate extensions when bridged to Swift, using the following:
Declare in the .h file
Typedef NSString * ViewControllerKey NS_STRING_ENUM; FOUNDATION_EXPORT ViewControllerKey const ViewControllerKeyTitle; FOUNDATION_EXPORT ViewControllerKey const ViewControllerKeySubtitle; FOUNDATION_EXPORT ViewControllerKey const ViewControllerKeySummary
Defined in the .m file:
ViewControllerKey const ViewControllerKeyTitle = @ "title"; ViewControllerKey const ViewControllerKeySubtitle = @ "subtitle"; ViewControllerKey const ViewControllerKeySummary = @ "summary"
Use the following in the swift file:
Print ("\ (ViewControllerKey.title)\ (ViewControllerKey.subtitle)\ (ViewControllerKey.summary)")
The difference between these two macro definitions is that NS_STRING_ENUM is deterministic, NS_EXTENSIBLE_STRING_ENUM is extensible, and can also be extended in swift.
_ _ VA_ARGS__
# # is an adhesive that binds the front and rear parts together, which means "character".
The _ _ VA_ARGS__ will be replaced by the argument list in the precompilation. Represents a list of variable parameters.
The function of adding # # before the # # _ _ VA_ARGS__ macro is that when the number of variable parameters is 0, the # # here plays the role of removing the previous redundant ones, otherwise there will be compilation errors.
# define BLOCK_EXEC (block,...) If (block) {block (_ _ VA_ARGS__);}; # ifdef DEBUG # define LogInfo (s,...) NSLog (@ "[LogInfo]% @", [[NSString stringWithUTF8String:__FILE__] lastPathComponent], _ _ LINE__, [NSString stringWithFormat: (s), # # _ VA_ARGS__]) # else # define LogInfo (s,...) # endif
This is the end of this article on "what are the common macros in iOS?". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.