目标C:[ClassName self]是什么?做? [英] Objective C: What does [ClassName self]; do?
问题描述
I'm looking through the source code for the CocoaHTTPServer project, more specifically the HTTPServer.m
file and I just don't understand this line:
connectionClass = [HTTPConnection self];
这做什么?它甚至如何编译?应该不是
What does this do (is it documented anywhere)? How does it even compile? Should it not be
connectionClass = [HTTPConnection class];
推荐答案
在此上下文中, (id)self
是在 NSObject
上定义的方法。它返回接收器。对于 Class
,它显然应该调用 - (Class)类
。
In this context, - (id)self
is a method defined on NSObject
. It returns the receiver. For a Class
it should obviously do the same as a call to the -(Class)class
.
类对象因此是完全成熟的对象,可以动态类型化,接收消息和从其他类继承方法。它们是特殊的,因为它们是由编译器创建的。
Class objects are thus full-fledged objects that can be dynamically typed, receive messages, and inherit methods from other classes. They’re special only in that they’re created by the compiler.
这篇关于目标C:[ClassName self]是什么?做?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!