添加带有“文本”的对象

发布于 2024-08-18 18:33:31 字数 681 浏览 8 评论 0原文

我很困惑或者只是找不到我需要的信息,当他们选择“saveDataround”按钮时,我想将一个对象保存在数组中,但是我似乎不知道如何使用文本“填充该对象” Round”:我收到“预期标识符”和“预期,;”第一行和第二行代码有错误。提前致谢。

[NSString *roundChoice = [NSString stringWithFormat:@"Round"];
self.round.text = roundChoice;]

- (IBAction)saveDataround {
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *recipient = [NSString stringWithFormat:@"%@/arrayChoiceRound", documentsDirectory];
    NSMutableArray *array = [[NSMutableArray alloc] init];
    [array addObject:round.text];
    [array writeToFile:recipient atomically:NO];
}

I'm stumped or just not finding info I need, I have an object that I want to save in an array when they select "saveDataround" button, however I can't seem to figure out how to populate the object with the text "Round": I'm getting an "Expected identifier" and "Expected , ;" errors on the first and second lines of code. Thanks in advance.

[NSString *roundChoice = [NSString stringWithFormat:@"Round"];
self.round.text = roundChoice;]

- (IBAction)saveDataround {
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *recipient = [NSString stringWithFormat:@"%@/arrayChoiceRound", documentsDirectory];
    NSMutableArray *array = [[NSMutableArray alloc] init];
    [array addObject:round.text];
    [array writeToFile:recipient atomically:NO];
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

樱花落人离去 2024-08-25 18:33:31

前两行代码在哪里实现?他们应该做什么?

以下是我在没有更多信息的情况下修改上述代码的方法:

// remove "[" from start of line & no need to use stringWithFormat here
NSString *roundChoice = @"Round";

// remove "]" from end of line
self.round.text = roundChoice;

- (IBAction)saveDataround {
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];

    // use stringByAppendingPathComponent here
    NSString *recipient = [documentsDirectory stringByAppendingPathComponent:@"arrayChoiceRound"];
    NSMutableArray *array = [[NSMutableArray alloc] init];

    // use self here (not required)
    [array addObject:self.round.text];

    [array writeToFile:recipient atomically:NO];

    // release the array
    [array release];
}

Where are the first two lines of code implemented? What are they supposed to do?

Here's how I would modify the above code without more info:

// remove "[" from start of line & no need to use stringWithFormat here
NSString *roundChoice = @"Round";

// remove "]" from end of line
self.round.text = roundChoice;

- (IBAction)saveDataround {
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];

    // use stringByAppendingPathComponent here
    NSString *recipient = [documentsDirectory stringByAppendingPathComponent:@"arrayChoiceRound"];
    NSMutableArray *array = [[NSMutableArray alloc] init];

    // use self here (not required)
    [array addObject:self.round.text];

    [array writeToFile:recipient atomically:NO];

    // release the array
    [array release];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文