将 NSArray 内容与 NSMutableString AppendString 连接
我试图迭代 NSArray 并在尝试将位置 i 处的数组内容连接到 NSMutableString 实例时不断收到编译器错误。
它只是告诉我“;”之前有一个“语法错误” 这并没有告诉我很多。 在这一行:
[output appendString:[widget.children objectAtIndex:i];
我知道我的语法一定有问题..
我的功能如下,
- (NSString *)readArray
{
NSMutableString *output = [[NSMutableString alloc] init];
int i;
int arraySize = widget.children.count;
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
for (i = 0; i < arraySize; i++)
{
[output appendString:[widget.children objectAtIndex:i]; (throws error here)
}
[pool release];
return output;
}
提前致谢
I'm trying to iterate through an NSArray and keep getting a compiler error right when i try concatenating the contents of my array at position i to my NSMutableString instance..
It just tells me that there's a "syntax error before ;" which doesn't tell me a whole lot.
at this line:
[output appendString:[widget.children objectAtIndex:i];
i know there must be something up with my syntax..
my function is as follows
- (NSString *)readArray
{
NSMutableString *output = [[NSMutableString alloc] init];
int i;
int arraySize = widget.children.count;
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
for (i = 0; i < arraySize; i++)
{
[output appendString:[widget.children objectAtIndex:i]; (throws error here)
}
[pool release];
return output;
}
thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
NSArray
有一个方法也可以完成您正在做的事情:此外,除非您在紧密循环中相当频繁地调用该函数,否则让它创建自己的自动释放池并没有太大优势。
NSArray
has a method that does exactly what you're doing as well:Also, unless you're calling that function fairly frequently in a tight loop there's not much advantage to having it create its' own autorelease pool.
你有一个未闭合的括号
最后需要
]]
而不是]
you have an unclosed bracket
you need
]]
at the end instead of]