Objective-C class names with a +

前端 未结 2 434
我在风中等你
我在风中等你 2021-01-18 20:25

Does a class name, say UIImage+Something or UIImageView+Somethingelse, mean that it acts like a custom UIImage or UIImageView

相关标签:
2条回答
  • 2021-01-18 21:03

    I think you are looking at the file names of Categories, not Classes. The plus character + is not allowed in class names or any other identifier in Objective-C.

    An Objective-C category is a way of adding methods (but not instance variables) to a class you don't necessarily have the source to. For example, if you frequently want to make upside-down copies of UIImages, you can use a category to add a upsideDownImage method onto the UIImage class.

    It's common to save this code in a file named UIImage+UpsideDown.m (with an accompanying header file, UIImage+UpsideDown.h).

    0 讨论(0)
  • 2021-01-18 21:06

    This is a naming convention when using an Objective-C Category to extend the functionality of a class. See the article: http://macdevelopertips.com/objective-c/objective-c-categories.html for a much better explanation.

    0 讨论(0)
提交回复
热议问题