来自 C++,这是我的问题:
我创建了这种类型的对象:
Size *one = [[Size alloc] initWithX: 3 andY: 1];
Size *two = [[Size alloc] initWithX: 4 andY: 7];
// etc...
Size *thirtythree = [[Size alloc] initWithX: 5 andY: 9];
(每个对象都有一个@property int x;
& ..)@property int y;
我存储在一个数组中,如下所示:
NSArray *arrayOfSizes;
arrayOfSizes = [NSArray arrayWithObjects:one,two,three,four,five,six,
seven,eight,nine,ten,eleven,twelve,thirteen,
fourteen,fifteen,sixteen,seventeen,eighteen,
nineteen,twenty,twentyone,twentytwo,
twentythree,twentyfour,twentyfive,twentysix,
twentyseven,twentyeight,twentynine,thirty,
thirtyone,thirtytwo,thirtythree nil];
现在我有一个类型的对象:
Myobject *myObject = [[Myobject alloc] initWithX: 5 andY: 3];
这也有一个@property int x;
& @property int y;
...
我想将它的值与数组中找到的对象的值进行比较,直到找到一个具有相似值的数组对象。但我不知道如何在 Obj-C 中做到这一点。(在 C++ 中,我会简单地使用vector v;
withv.size();
和v[x];
..etc ......我想......)
这就是我要找的东西.. :)
while( !wholeOfArrayOfSizesChecked && !found)
{
if ( // x & y of object in array is equal to x & y of myObject )
{
found = YES;
}
else if( // whole of array checked)
{
wholeOfArrayOfSizesChecked = YES;
}
else
{
//move on to the next object of the array..
}
}
提前感谢您的帮助!