我已经添加了几个class Objects
到NSMutableArray
. 它似乎有效,但是我现在想访问存储在数组中的类对象内部的变量,但是我现在遇到了一些错误。
最初,我有一个NSDictionary
条目,它们都NSString
基于我传递 /s 的方法的目的,即NSArray
获取NSDictionary
字典中的每个条目并将其放入正确类型的变量中。然后这个NSObject
变量被传递回它被调用的地方。
下面是我用来实现这一点的代码。
响应.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 循环中调用的类方法
搜索结果列表.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;
}
所以从这里开始,我最终回到了response.m的 for 循环中,我在其中调用searchObjectArray addObject:searchResultList];
以捕获返回的类对象。
此时我有两个问题。
首先,我NSObject
是否正确捕获了类
其次,一旦我将所有类对象添加到数组中,我如何才能访问数组中特定对象的变量?
我问第二个问题的原因是因为我想将此数组传递给排序方法,该方法根据数组中对象的一个或多个变量进行排序。
任何帮助将不胜感激。