简体   繁体   English

我正在学习的“ Objective-C”中有多少是通用的Objective-C,而不是Apple的框架?

[英]How much of the “Objective-C” I'm learning is universal Objective-C, and not Apple's frameworks?

This question is related to one of my others about C: What can you do in C without “std” includes? 这个问题与我的另一个有关C的问题有关: 如果没有“ std”包含,您可以在C中做什么? Are they part of “C,” or just libraries? 它们是“ C”的一部分,还是只是库?

I've become curious lately as to what is really contained the the core Objective-C language, and what parts of the Objective-C I've done for iPhone/OS X development is specific to Apple platforms. 最近,我对核心Objective-C语言真正包含的内容以及我为iPhone / OS X开发所做的Objective-C的哪些部分特定于Apple平台感到好奇。

I know that things like syntax are the same, but for instance, is NSObject and its torrent of NS -subclasses actually part of "standard" Objective-C? 我知道语法之类的东西是相同的,但是例如, NSObject及其NS子类激流是否实际上是“标准” Objective-C的一部分? Could I use them in, say, Windows? 我可以在Windows中使用它们吗?

What parts are universal for the most part, and what parts would I only find on an Apple platform? 哪些部分在大多数情况下是通用的,而我只能在Apple平台上找到哪些部分?

If you want, giving an example of Objective-C used elsewhere as an example of what is more "universal" would help me as well. 如果愿意,举一个在其他地方使用的Objective-C示例作为更“通用”的示例也将对我有帮助。

Thanks! 谢谢! =) =)

There are only two current implementations of the core Objective-C libraries, previously known as the NextStep (hence NS prefixes) and OPENSTEP: GNUStep and Apple's OS X. On Linux, if you maintain compatibility with the OPENSTEP specification, GNUStep works very well. 目前只有两种核心Objective-C库的实现,以前称为NextStep(因此带有NS前缀)和OPENSTEP: GNUStep和Apple的OSX。在Linux上,如果您保持与OPENSTEP规范的兼容性,则GNUStep可以很好地工作。 However, the specification is ancient, and modern code for OS X will likely not work correctly (especially in the UI area). 但是,该规范是古老的,并且OS X的现代代码可能无法正确工作(尤其是在UI区域)。 The situation on Windows is even worse. Windows上的情况更糟。

You can use the Objective-C language anywhere GCC supports the build target. 您可以在GCC支持构建目标的任何地方使用Objective-C语言。 The "NS" classes are not part of the language proper. “ NS”类不是语言本身的一部分。

If you're trying to maintain compatibility across platforms in your code base, stick to C or C++, only move UI specific behavior to Objective-C. 如果您要维护代码库中跨平台的兼容性,请坚持使用C或C ++,仅将特定于UI的行为移至Objective-C。

Objective-c is C plus these keywords: Objective-c是C加上这些关键字:

@interface, @implementation, @protocol, @end, @private, @protected, @public, @try,
@throw, @catch, @finally, @class, @selector, @encode, @"string", @synchronized,
@property, @synthesized

Plus the message sending syntax: [anObject aMessage]; 加上消息发送语法: [anObject aMessage];

EDIT 编辑

Given that you have an objective-c compiler such as GCC you still need an Objective-c runtime in order to make the above stuff work. 假设您有一个诸如GCC之类的Objective-c编译器,您仍然需要一个Objective-c运行时才能使上述内容正常工作。 eg [anObject aMessage] is actually compiled to 例如[anObject aMessage]实际上被编译为

objc_msgSend( anObject, @selector(aMessage));

...therefore the symbol objc_msgSend is one of several that must exist at runtime. ...因此,符号objc_msgSend是运行时必须存在的几种符号之一。 In theory this could be provided by a compiler intrinsic but in practice you are probably going to link to an Objective-c runtime library - a quick search of my hard drive shows i have three installed:- Apple's , GNUStep , and Cocotron - there are more but Apple's (open source) is without doubt the most important and influential. 从理论上讲,这可以由内在的编译器提供,但是在实践中,您可能会链接到Objective-c运行时库-快速搜索我的硬盘驱动器会显示我已安装了三个: -AppleGNUStepCocotron-还有更多,但是苹果(开源)无疑是最重要和最有影响力的。

With an Objective-c compiler and runtime - but without any Apple Objective-c frameworks ( NSObject , etc.) - you have a fabulous and very useful C-with-Classses that is much simpler (where simpler means 'better for me') than C++. 有了一个Objective-c编译器和运行时-但没有任何Apple Objective-c框架( NSObject等)-您拥有一个神话般且非常有用的 C-with-Classses,它简单得多(其中简单意味着“对我而言更好”)比C ++

None of the class library is part of the language itself. 类库都不是语言本身的一部分。 If you want to see the core Objective-C types, look in include/objc. 如果要查看核心的Objective-C类型,请查看include / objc。 The core language itself, without any added library, is really scant and not particularly useful. 核心语言本身,没有任何添加的库,确实很少,而且不是特别有用。

In practice, however, Objective-C is just about never used outside of the context of an OpenStep framework like Cocoa or GNUstep. 但是,实际上,几乎从未在像Cocoa或GNUstep这样的OpenStep框架的上下文之外使用Objective-C。 So you could view that as the de facto standard library, in which case Foundation is almost universal. 因此,您可以将其视为事实上的标准库,在这种情况下,Foundation几乎是通用的。 (Not 100% of Foundation is that way, but the majority is.) (不是基金​​会的100%这样,但多数是。)

You can a lot on Windows using Cocotron , which is a free implementation of Apple's frameworks. 您可以在Windows上使用Cocotron进行很多操作 ,这是Apple框架的免费实现。 It's not complete, and you may run into bugs, but if you're lucky, you can compile your Xcode project as a Windows app without too many changes. 它并不完整,您可能会遇到bug,但是如果幸运的话,您可以将Xcode项目作为Windows应用程序进行编译,而无需进行太多更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM