都是“核心(基础、数据、图形等)”吗?用类似 C 的语法编写?
我相信这个问题本身就说明了问题,而且我知道对于你们中的许多人来说,这个问题可能看起来很迟钝。我只是想知道 Objective-C 中以 Core
开头的所有内容是否都是用普通的 C
编写的。
我的猜测是“是的,是的。”,但我想 100% 确定;)
非常感谢。
编辑:查看答案,我现在意识到我应该询问 Core
库中的语法。
它是否总是类似于 C 语法:void myFunction(int num);
而不是 - (void) myFunction:(int) path;
?
到目前为止,在 Obj-C 中我不太喜欢的一件事是混合 ()/dot/->;语法与 [] 语法。我觉得确实不太优雅...
I believe the question speaks for itself, and I know that to many of you this question might seem retarded. I just wonder if everything, in Objective-C, that starts with Core
is written in a plain C
.
My guess is "Yes, it is.", but I want to be sure for 100% ;)
Many thanks.
EDIT: Looking at the answers I now realise I should have asked about the syntax in Core
libraries.
Is it always C
like syntax: void myFunction(int num);
and not - (void) myFunction:(int) path;
?
So far one thing that I am not too fond of, in Obj-C, is mixing ()/dot/-> syntax with [] syntax. I think it really isn't elegant...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
无意冒犯,但正确的答案是“谁在乎”? (开玩笑)
不过,老实说,任何系统库都可以用几乎任何他们想要的方式编写。可能是 Objective-C、C、C++ 和汇编程序的组合;可能性较小(但技术上仍然可行)的选项包括 Pascal、Fortran、LOGO 或手工组装的机器代码。
如果您想要系统库中代码组合的示例,请查看开源 Java 库。您将看到
java.*
包是用 Java 和 C 的组合编写的;某些端口可能包括零件组装。只要接口与 Objective-C 兼容,这就是您真正需要担心的。
此外,唯一能回答这个问题的人可能是苹果公司的人,而且可能不被允许告诉你。
No offense, but the proper answer is "who cares"? (insert tongue in cheek)
Honestly, though, any system libraries can be written in pretty much whatever they want. There's probably a combination of Objective-C, C, C++, and assembler; less likely (but technically still possible) options include Pascal, Fortran, LOGO, or hand-assembled machine code.
If you want an example of the combinations of code in system libraries, take a look at the open-sourced Java libraries. You will see that the
java.*
packages are written in a combination of Java and C; some ports may include assembly for parts.As long as the interface is Objective-C compatible, that's all you really need to worry about.
Also, the only people who can answer that are probably at Apple, and probably aren't allowed to tell you.
它是用“无论如何”编写的(一点 ObjC,很多 C,一点 asm),但关键是它呈现的接口是纯 C 的。
我会注意到 Core Data 和 Core Image 呈现 ObjC 接口尽管。
It's written in "whatever" (a bit of ObjC, a lot of C, a bit of asm), but the key thing is that the interface it presents is pure C.
I'll note that Core Data and Core Image present ObjC interfaces though.
是的,Appkit / UIKit 是建立在其之上的,他们做了一些技巧来使 ObjC 和 Core* 之间的交互非常高效(称为“免费桥接”)
Yep it is - Appkit / UIKit is built on top of that, and they've done some tricks to make the interaction between ObjC and Core* to be very efficient (called "Toll-free Bridging")
毕竟它是 Objective-C;该语言是直接 C 之上的一个非常小的语法层,带有运行时库来提供动态行为。
混合 C 和 Objective-C 是环境中经常遇到且自然的一部分。
正如其他人所说,用于实现各种 Core* 框架的语言是一个通常不应该关心的实现细节。话虽如此,CoreFoundation 的很大一部分是用 Objective-C 编写的,而且还在不断增长。
It is Objective-C after all; the language is a very small layer of syntax on top of straight C with a runtime library to provide the dynamic behaviors.
Mixing C and Objective-C is a very oft encountered and natural part of the environment.
As others have said, the languages used to implement the various Core* frameworks is an implementation detail that should generally be of no concern. With that said, a good sized and growing chunk of CoreFoundation is written in Objective-C.