gpt4 book ai didi

cocoa - 将变量插入 NSMutableArray 对象

转载 作者:行者123 更新时间:2023-12-03 17:30:53 25 4
gpt4 key购买 nike

我想将预定义的字符串添加到 NSMutableArray 的对象中。我以为你会使用 %@,但显然下面的代码执行得不好。提前谢谢您

arrayData = [[NSMutableArray alloc]
initWithObjects:@"%@ you look tired." name,
@"Why do you smell so bad?",
@"I have to go potty!",
@"%@ put your pants on!" name,
@"Mommy!",
@"Daddy!",
@"NOOOOOO!",
@"When are we going to get there?",
@"I HATE YOU!",
nil];

最佳答案

%@stringWithFormat: 调用中有效。您的代码应如下所示:

arrayData = [[NSMutableArray alloc] initWithObjects:
[NSString stringWithFormat:@"%@ you look tired.", name],
@"Why do you smell so bad?",
@"I have to go potty!",
[NSString stringWithFormat:@"%@ put your pants on!", name],
@"Mommy!",
@"Daddy!",
@"NOOOOOO!",
@"When are we going to get there?",
@"I HATE YOU!",
nil];

关于cocoa - 将变量插入 NSMutableArray 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4124510/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com