にいくつか追加しclass Objects
ましたNSMutableArray
。うまくいったようですが、配列に保存したクラスオブジェクト内の変数にアクセスしたいのですが、現在いくつかのエラーが発生しています。
最初に、/s のこれを渡すメソッドの目的に基づいたNSDictionary
すべてのエントリがあります。これは、ディクショナリ内の各エントリを取得し、正しい型の変数に配置することです。次に、変数の this は、それが呼び出された場所に戻されます。NSString
NSArray
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;
}
したがって、ここから、 response.mの for ループに戻ります。ここで呼び出しsearchObjectArray addObject:searchResultList];
て、返されたクラス オブジェクトをキャプチャします。
この時点で、2 つの質問があります。
まず、NSObject
クラスを正しくキャプチャしていますか
次に、すべてのクラス オブジェクトを配列に追加したら、配列内の特定のオブジェクトの変数にアクセスするにはどうすればよいでしょうか。
2 番目の質問をする理由は、この配列を、配列内にあるオブジェクトの 1 つ以上の変数に基づいて並べ替える並べ替えメソッドに渡したいからです。
どんな助けでも大歓迎です。