Mikuro
Crotchety UI Nitpicker
I'm pretty new to C and Cocoa. I'm coming mostly from REALbasic. Forgive me if this question is a little newbish.
I want to make an array that works more or less like REALbasic's. That is to say, I want to be able to dynamically resize the array and append new elements. NSArray isn't what I need, because it's only suitable for objects, and the "int myInt[10]" kind of array isn't it either, because as far as I can tell, there's no way to resize such arrays after their creation (PLEASE correct me if I'm wrong!)
I think what I need is a C++ vector. After much hair-pulling, I finally figured out how to create and use C++ vectors in my Objective-C code, following these surprisingly easy steps:
1. Rename my "*.m" file "*.mm" (yeesh! That took me WAY too long to figure out)
2. Add "#include <vector>" to the top of my .mm file.
3. Declare my vector like so: std::vector<NSRect> rectVector;
Great. The problem is, I can't figure out how to declare vectors in a .h file. It tells me "vector: No such file or directory", and gives me a "parse error before 'std'" (and a few warnings about C++ destructors).
I've tried changing the file type of my .h file using Xcode's info window (which is what renaming the .m file to .mm does automatically), but to no avail.
So, I have two questions:
1. Is there a native Objective-C analog of C++ vectors? It seems like there'd have to be, but...damned if I can find it.
2. If not, is it possible to use C++ vectors as part of an Objective-C class (i.e., in a .h file)?
What I'm trying to do specifically is create a list of NSRects that I can append to, and also a two-dimensional resizeable array of bools (though I can work around the 2D bool part easily enough, at least for now). I have no idea how big the list will need to be until runtime (could be anywhere from 0 to many thousands of elements). And it needs to be accessible from any method in its owning class.
I want to make an array that works more or less like REALbasic's. That is to say, I want to be able to dynamically resize the array and append new elements. NSArray isn't what I need, because it's only suitable for objects, and the "int myInt[10]" kind of array isn't it either, because as far as I can tell, there's no way to resize such arrays after their creation (PLEASE correct me if I'm wrong!)
I think what I need is a C++ vector. After much hair-pulling, I finally figured out how to create and use C++ vectors in my Objective-C code, following these surprisingly easy steps:
1. Rename my "*.m" file "*.mm" (yeesh! That took me WAY too long to figure out)
2. Add "#include <vector>" to the top of my .mm file.
3. Declare my vector like so: std::vector<NSRect> rectVector;
Great. The problem is, I can't figure out how to declare vectors in a .h file. It tells me "vector: No such file or directory", and gives me a "parse error before 'std'" (and a few warnings about C++ destructors).
I've tried changing the file type of my .h file using Xcode's info window (which is what renaming the .m file to .mm does automatically), but to no avail.
So, I have two questions:
1. Is there a native Objective-C analog of C++ vectors? It seems like there'd have to be, but...damned if I can find it.
2. If not, is it possible to use C++ vectors as part of an Objective-C class (i.e., in a .h file)?
What I'm trying to do specifically is create a list of NSRects that I can append to, and also a two-dimensional resizeable array of bools (though I can work around the 2D bool part easily enough, at least for now). I have no idea how big the list will need to be until runtime (could be anywhere from 0 to many thousands of elements). And it needs to be accessible from any method in its owning class.