具有+的Objective-C类名称 [英] Objective-C class names with a +
问题描述
一个类名,例如UIImage+Something
或UIImageView+Somethingelse
,是否意味着它像自定义的UIImage
或UIImageView
一样起作用?
Does a class name, say UIImage+Something
or UIImageView+Somethingelse
, mean that it acts like a custom UIImage
or UIImageView
?
推荐答案
我认为您正在查看的是类别"而不是类"的文件名.在类名称或Objective-C中的任何其他标识符中,不允许使用加号+
.
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.
Objective-C类别是一种将方法(但不包括实例变量)添加到您不一定有其来源的类的方法.例如,如果您经常要制作UIImage的上下副本,则可以使用类别将upsideDownImage
方法添加到UIImage类上.
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.
通常将此代码保存在名为UIImage+UpsideDown.m
的文件中(带有随附的头文件UIImage+UpsideDown.h
).
It's common to save this code in a file named UIImage+UpsideDown.m
(with an accompanying header file, UIImage+UpsideDown.h
).
这篇关于具有+的Objective-C类名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!