What are the equivalent for this Java data type in Objective-C
short[] data;
byte[] data;
char[] Array;
LinkedList< byte[] > varName
LinkedList< short[] > varName;
I'm new on this, I'll apreciate your help.
Thank You.
What are the equivalent for this Java data type in Objective-C
short[] data;
byte[] data;
char[] Array;
LinkedList< byte[] > 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
short array is supported
short[] data; //works
see: Objective-C equivalent for java byte[]
and: 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
char array is supported
char byteArray[] = {0x12,0x13,0x53}; //works
LinkedList is not supported
I found some alternative on CocoaDev, read more here: 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
The first few examples are basically the same in Objective-C, with a few reservations:
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. Otherwise, explicitly specify its size (as in T arr[1000]
). You also have the option of representing these as pointers (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. Please check out the documentation on NSArray
if you haven't already done so.
As for the linked lists, Cocoa doesn't have a built-in linked list implementation. 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. Be aware that Objective-C does not have parametric polymorphism; thus, you cannot generalize a type over other types, as would be necessary for LinkedList
to hold values of various types. 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).
Here is an array of integers. Just change it to be short or char.