Objective-C 导入,使用 Cygwin 的原始类型
我了解 Objective-C 的基本语法,已经安装了 Cygwin,并且想要进行实验。 但是我不确定两件事: 我要导入什么,以及 原始类型名称是什么。 有人能帮我吗?
I understand the basic syntax of Objective-C, have installed Cygwin, and want to experiment. However i am unsure of two things:
What i would import, and
what the primitive type names are.
Can someone help me?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以继承的唯一对象称为
Object
。 请记住,它提供的功能远不及 NeXTStep 或 Cocoa 的NSObject
的功能。Object
甚至没有像引用计数这样的东西。 为了获得与 NSObject 相同类型的引用计数内存管理,您需要自己实现它。链接时,您必须确保与
-lobjc
链接,这是Object
的定义所在(我认为)。另一个大问题是静态字符串实例,即代码中出现
@"like this"
的字符串。 在 GNU 运行时中,字符串的静态实例需要具有特定的 ivar 布局,即:编译时,可以使用标志
-fconstant-string-class=MyStaticStringClass
。 您可以为字符串类提供任何您喜欢的方法,但它必须只有两个 ivars,并且它们的顺序必须正确。 如果你不想使用 Objective-C 风格的字符串,那么你不必定义静态字符串类。 如果您确实定义了静态字符串类,它应该能够复制动态字符串类(即在运行时分配的字符串对象)的行为,以便您可以在给定情况下使用其中任何一个。对于命令行实用程序和基本应用程序,我选择不使用 Cocoa 或 GNUstep,而是定义我自己的类。 它有很多缺点,但我发现 Objective-C 中的对象抽象和变形比我编程的其他语言更容易实现。
The only object you can inherit from is called
Object
. Bare in mind that this offers nowhere near the same amount of functionality as NeXTStep's or Cocoa'sNSObject
.Object
does not even have anything like reference counting. In order to get the same sort of reference counting memory management thatNSObject
has you'll need to implement it yourself.When linking, you have to make sure you link with
-lobjc
, this is where the definition ofObject
lies (I think).The other big catch is with static string instances, i.e. strings in code that appear
@"like this"
. With the GNU runtime, static instances of strings need to have a particular ivar layout, which is:When compiling, you can use the flag
-fconstant-string-class=MyStaticStringClass
. You can provide whatever methods you like for the string class but it must have only two ivars and they must be in the right order. If you don't want to use Objective-C style strings, then you don't have to define a static string class. If you do define a static string class it should be able to replicate the behaviour of your dynamic string class (i.e. string objects that are allocated during run time) so that you can use either in a given situation.For command-line utilities and basic apps I choose not to use Cocoa or GNUstep but rather define my own classes. It has many drawbacks, but I find that object abstraction and metamorphism in Objective-C is much easier to implement than in the other languages that I program in.