简体   繁体   English

如何一起构造应该在Obj-C中相应执行的方法

[英]How to structure methods together that are supposed to be executed consequtively in Obj-C

I am creating a language quiz app to learn Obj-C and I am having a hard time understanding the proper way to structure such the information processing functions. 我正在创建一个语言测验应用程序来学习Obj-C,并且我很难理解构造这种信息处理功能的正确方法。 So far: 至今:

I have a collection of spanish words and their definitions in a separate text file. 我在单独的文本文件中收集了西班牙语单词及其定义。 Here's the main parts of the code that I am having trouble implementing: 这是我难以实现的代码的主要部分:

@implementation SGLDictionary

-(NSString*)makeStringFromFile:(NSString *)myFileName {
    //read file and save to *string

return string;

} }

-(NSArray *)getContentFromString:(NSMutableString *)string {
     //Here the string is trimmed and deheadered so only the content is left and returned as an NSArray.
return Array;

} }

-(NSMutableDictionary *)makeDictionaryFromArray:(NSArray *)array{
    //make the array mutable and form it into a dictionary by looping over it
return spanishToEnglishDictionary;

} }

How do you later initialize an instance of the SGLDictionary class and call the methods so they are executed on the instance one by one? 您以后如何初始化SGLDictionary类的实例并调用这些方法,以便它们在该实例上一个接一个地执行? I'm not sure how this works because I thought the methods that change data don't return any (they return void ). 我不确定这是如何工作的,因为我认为更改数据的方法不会返回任何值(它们return void )。

- (NSMutableDictionary *)dictionaryFromFile:(NSString *)file
{
    return [self makeDictionaryFromArray:[self getContentFromString:[self makeStringFromFile:file]]];
}

Isn't it enough for your question? 这还不够您的问题吗?

You can invoke this method like 您可以像这样调用此方法

SGLDictionary *sgl      = [[SGLDictionray alloc] init];
NSMutableDictionry *dic = [sgl dictionaryFromFile:file];

example : if u have a method like 示例:如果您有类似的方法

-(BOOL)myInteger:(int)number1 andSecond:(int)number2;

then lemme explain what is happenening - 然后lemme解释发生了什么-

Method name - myInteger andSecond (Yes this is the full method name). 方法名称- myInteger andSecond (是的,这是完整的方法名)。 -(BOOL) this is your RETURN TYPE . -(BOOL)这是您的RETURN TYPE

(int)number1 -- This int is the type of FIRST parameter named - number1. (int)number1此int是名为-number1的FIRST参数的类型。 (int)number2 -- This int is the type of SECOND parameter named - number2. (int)number2此int是名为-number2的SECOND参数的类型。

andSecond -- this is the continuation of the METHOD NAME. 第二-这是方法名称的延续。

and this is how u will call this method 这就是你将如何调用此方法

 [self myInteger:4 andSecond:5];

I dont know if i understood ur question properly but i guess it helps 我不知道我是否正确理解了您的问题,但我想这会有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM