NSMutableArray。对象值没有被替换

发布于 2024-12-28 20:45:26 字数 843 浏览 1 评论 0原文

我有一个 NSMutableArray,我想更改特定对象的值。

然而,它并没有改变。

以下是我的代码:

//create two array to store data later
NSMutableArray *feelingsArray = [[NSMutableArray alloc] init];


// get paths from root direcory

NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);

// get documents path

NSString *documentsPath = [paths objectAtIndex:0];

// get the path to our Data/plist file

NSString *feelingsPath = [documentsPath stringByAppendingPathComponent:@"Feeling.plist"];



//This copies objects of plist to array if there is one
[feelingsArray addObjectsFromArray:[NSArray arrayWithContentsOfFile:feelingsPath]];

//replace object at particular location
[datesArray replaceObjectAtIndex:number withObject:feeling.text];

我需要进行任何更改或添加一些代码(例如同步等)吗?

请提供一些指导。

I have a NSMutableArray and I want to change the value of a particular object.

However, it's not changing.

Below is my code:

//create two array to store data later
NSMutableArray *feelingsArray = [[NSMutableArray alloc] init];


// get paths from root direcory

NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);

// get documents path

NSString *documentsPath = [paths objectAtIndex:0];

// get the path to our Data/plist file

NSString *feelingsPath = [documentsPath stringByAppendingPathComponent:@"Feeling.plist"];



//This copies objects of plist to array if there is one
[feelingsArray addObjectsFromArray:[NSArray arrayWithContentsOfFile:feelingsPath]];

//replace object at particular location
[datesArray replaceObjectAtIndex:number withObject:feeling.text];

Do I need to make any changes or add some code like synchronise etc.?

Please provide some guidance.

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

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

发布评论

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

评论(1

墟烟 2025-01-04 20:45:26

不应该

[datesArray replaceObjectAtIndex:number withObject:feeling.text];

[feelingsArray replaceObjectAtIndex:number withObject:feeling.text];

Shouldn't

[datesArray replaceObjectAtIndex:number withObject:feeling.text];

be

[feelingsArray replaceObjectAtIndex:number withObject:feeling.text];

?

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