简体   繁体   English

等同于Objective-C的Java数据类型

[英]Java Data Type Equivalent to Objective-C

What are the equivalent for this Java data type in Objective-C 在Objective-C中此Java数据类型的等效项是什么

short[] data; short []数据;
byte[] data; byte []数据;
char[] Array; char []数组;
LinkedList< byte[] > varName LinkedList <byte []> varName
LinkedList< short[] > varName; LinkedList <short []> varName;

I'm new on this, I'll apreciate your help. 我对此并不陌生,我会感谢您的帮助。

Thank You. 谢谢。

see: http://www.techotopia.com/index.php/Objective-C_2.0_Data_Types 参见: http : //www.techotopia.com/index.php/Objective-C_2.0_Data_Types
short array is supported 支持短数组

short[] data; //works

see: Objective-C equivalent for java byte[] 参见: 相当于java字节的Objective-C []
and: http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSMutableData_Class/Reference/NSMutableData.html 和: http : //developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSMutableData_Class/Reference/NSMutableData.html
byte array alternative 字节数组替代

NSString *myString = @"string for data1";
const char *utfMyString = [myString UTF8String];
NSMutableData *data1 = [NSMutableData dataWithBytes:utfMyString length:strlen(utfMyString)+1];

see: Byte array in objective-c 请参阅: Objective-C中的字节数组
char array is supported 支持char数组

char byteArray[] = {0x12,0x13,0x53}; //works

LinkedList is not supported 不支持LinkedList
I found some alternative on CocoaDev, read more here: http://www.cocoadev.com/index.pl?LinkedList 我在CocoaDev上找到了一些替代方法,请在此处阅读更多信息: http : //www.cocoadev.com/index.pl? LinkedList
and also read this, I think too that you don't always need to use LinkedList solution: Creating Linked Lists in Objective C 并阅读此书,我也认为您不必总是使用LinkedList解决方案: 在Objective C中创建链接列表

The first few examples are basically the same in Objective-C, with a few reservations: 前几个示例与Objective-C基本相同,但有一些保留:

short data[] = {...};
byte data[] = {...};
char data[] = {...};

The reservation is that these are not dynamic arrays . 保留意见是这些不是动态数组 The compiler needs to know their sizes; 编译器需要知道它们的大小。 that is, if you use the T arr[] notation, you need to immediately assign a value to it. 也就是说,如果使用T arr[]表示法,则需要立即为其分配一个值。 Otherwise, explicitly specify its size (as in T arr[1000] ). 否则,显式指定其大小(如T arr[1000] )。 You also have the option of representing these as pointers ( T* arr ). 您还可以选择将它们表示为指针( T* arr )。

In Objective-C, we usually like to have a greater level of flexibility than plain C arrays will give us, so we use NSArray for similar tasks frequently. 在Objective-C中,我们通常希望具有比普通C数组更高的灵活性,因此我们经常将NSArray用于类似任务。 Please check out the documentation on NSArray if you haven't already done so. 如果尚未完成,请查阅NSArray文档

As for the linked lists, Cocoa doesn't have a built-in linked list implementation. 至于链表,Cocoa没有内置的链表实现。 It's rare that you'll actually end up using a linked list in Objective-C idiom, but if you need it, it's really quite easy to implement. 最终在Objective-C惯用语中最终使用链接列表的情况很少见,但是如果需要的话,实现起来确实很容易。 Be aware that Objective-C does not have parametric polymorphism; 要知道,Objective-C中具有参数多态性; thus, you cannot generalize a type over other types, as would be necessary for LinkedList to hold values of various types. 因此,您不能在其他类型上泛化一个类型,这对于LinkedList保留各种类型的值是必要的。 And since primitives can't be cast to objects coherently, you can't create a generic LinkedList class that can hold primitives or objects (you can unify primitives under void* , but not objects, since they require memory management). 而且由于无法将基元连贯地转换为对象,因此无法创建可以LinkedList元或对象的通用LinkedList类(您可以在void*下统一基元,但不能统一对象,因为它们需要内存管理)。

Here is an array of integers. 这是整数数组。 Just change it to be short or char. 只需将其更改为short或char。

Create an array of integers property in Objective C 在目标C中创建整数数组

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

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