Итак, я довольно новичок в объекте c, и я создаю класс согласования, внутри класса у меня есть метод, который добавляет слово из книги в aa _ListofPtrsToUniqueWords, uniqueWord is другой класс, который я создал для хранения каталогизируемого слова, хорошо в C++ мой метод Добавляет UniqueWord к массиву уникальных слов, если он уже существует, он пропускает слово, но он добавляет номер строки в список _CurrentLineArray, это метод i используется на C++Добавление «->» в Objective C
/* Attempts to add a word to the concordance. If it already exists, the existing entry is updated with the new line. */
void Concordance::add(const string word, const int line)
{
int insertion, index;
UniqueWord *uw = new UniqueWord(word, line);//creates the uniqueWord object
insertion = newIndex(*uw, index);//figures out where my word belongs in my array to be alphabetized
if (insertion == -1)
{
// The word already exists - add a line number.
delete uw;
ListOfUniqueWordsPtrs[index]->addLine(line);//I'm trying to do this in Objective C.
//My friend recommended i do this but i never asks what exactly does it do, addLine is a Unique word method
}
else
{
ListOfUniqueWordsPtrs.insert(ListOfUniqueWordsPtrs.begin() + insertion, uw);
}
}
Теперь я пытаюсь сделать то же самое в Objective C, но я не понимаю, что делает этот символ «->», мой друг просто рекомендовал я сделать это, но я не понимаю что он делает и как это можно сделать в Objective C
-(void) add:(NSString *)currentWordBeingCatalog and:(NSNumber*)CurrentLineNumber{
NSInteger insertion, index=0;
UniqueWord *CurrentWord=[[UniqueWord alloc] initWithString:currentWordBeingCatalog andline:CurrentLineNumber];
insertion=[self NewIndexToFindOutIf:CurrentWord is:[NSNumber numberWithLong:index]];
if(insertion==-1){
/*If the word already exist, it would delete the word and add the line number to the _linenumber NSMutableArray*/
CurrentWord=NULL;
[_ArrayOfPtrsToUniqueWords objectAtIndex:index]->[CurrentWord addALineNumberToCurrentLineNumberArray:CurrentLineNumber]];//This is where i'm trying to figure out what to do
}else{
[_ArrayOfPtrsToUniqueWords insertObject:CurrentWord atIndex:(0+insertion)];
}
}
Я надеюсь, что я дать вам ребята достаточно информации по этому коду, спасибо
Это может быть проще, если ваше именование было более похожим между двумя, но это то, что вы хотите? '[[_ArrayOfPtrsToUniqueWords objectAtIndex: index] addALineNumberToCurrentLineNumberArray: CurrentLineNumber]]' Вы не хотите '->'. Вы получаете объект через 'objectAtIndex', затем вызываете что-то, добавляя к нему еще один набор' [] 'и добавляя имя сообщения. Посмотрите на '[[UniqueWord alloc] initWithString ...' в качестве примера. – crashmstr