我已将几个class Objects
添加到NSMutableArray
中。它似乎工作,但我想现在访问我已经存储到数组中的类对象内的变量,但我现在遇到一些错误。如何从NSMutableArray访问NSObject类变量进行排序
起初我是我传递NSDictionary
这NSArray
/太是走在字典中的每个条目,并将其放置到正确类型的变量的方法的所有NSString
基于目的条目的NSDictionary
。然后这个变量的这个NSObject
被传回到它被调用的地方。
下面是我用来实现此目的的代码。
response.m
// initalise NSOject Class
SearchResultList *searchResultList = [[SearchResultList alloc]init];
// Create mutableArray with compacity (compacity is based of the current array of NSDictionarys (entries are strings))
NSMutableArray *searchObjectArray = [[NSMutableArray alloc] initWithCapacity:[filteredArray count]];
// count to track progress of the array
int myCount = 0;
// for loop goes through the array passing each object in the array over to the search class object
for (id obj in filteredArray) {
// Pass current array object over to the NSObject Class Method, this method assigns the entires of the NSDictionary object to the variables of the object class coorect type values
[searchResultList assignSearchData:filteredArray[myCount]];
// This is where I capture the returning NSObject Class (at least I think thats whats happening.
[searchObjectArray addObject:searchResultList];
// increments count
myCount ++;
}
//..
这是类方法被调用内部的for循环
SearchResultList.m
//return is of type, SearchResultList which is the object class itself... not sure if this is 100% correct.
- (SearchResultList *)assignSeriesSearchData:(NSMutableDictionary*)tempDict
{
//add all of the NSDictionary entries into their own variables of the correct type such as
// initalize DOORID - NSInteger
doorID = [[tempDict valueForKey:@"DOORID"] integerValue];
// initalize DOORDESC - NSString
doorDesc = [tempDict valueForKey:@"DOORDESC"];
// initalize DOOROPEN - BOOL
doorOpen = [[tempDict valueForKey:@"DOOROPEN"] boolValue];
// initalize DOORLETTER - char
doorLetter = [[tempDict valueForKey:@"DOORLETTER"] UTF8String];
//...
//then I return the NSObject Class to the place where it was called
return self;
}
从这里
所以,我结束回到回复for回复.m我在那里调用searchObjectArray addObject:searchResultList];
来捕获返回的类对象。
在这一点上,我有两个问题。
首先,我是不是正确捕获的NSObject
类
二,一旦我添加了所有的类对象的数组的我怎么可能再存取权限的特定对象的变量数组中?
我问第二个问题的原因是因为我想将此数组传递给排序方法,该排序方法基于数组中对象的一个或多个变量进行排序。
任何帮助将不胜感激。
NSLog(@"%@", myobj.doorID);
如果我添加了'NSObject * myobj = [searchObjectArray objectAtIndex:0]; NSLog(@“%@”,myobj);'在for循环之后,当我将鼠标移到myobj上时添加一个断点我可以看到所有变量及其值可用..我只是不知道如何单独访问它们... – HurkNburkS 2012-08-13 04:08:39