0
理想情况下,我想在NSMutableArray中创建一个函数添加对象,然后在另一个函数中对此数组执行任何操作。在另一个函数中声明的NSMutableArray中添加对象
这里是我一直试图做最近,当然这是行不通的,但它给你的就是我想要做的一个想法:
- (void)someThing
{
(...)
NSMutableArray *arrayOfThings = [[NSMutableArray alloc] init];
while (theObject = [aNSEnumerator nextObject]) {
const char *theObject_fixed = [theObject UTF8String];
function_something(theObject_fixed);
}
// do something with arrayOfThings
}
void function_something(const char *file)
{
(...)
unsigned int *p = memmem(buffer, fileLen, bytes, 4);
NSMutableString *aString = [[NSMutableString alloc] initWithCapacity:48];
unsigned long off_to_string = 0x10 + 4 + ((void *)p) - ((void *)buffer);
for (unsigned long c = off_to_string; c<off_to_string+0x30; c++)
{
[aString appendFormat:@"%.2x", (int)buffer[c]];
}
NSLog(@"%s: %@", file, aString);
[arrayOfThings addObject:[aString copy]];
free(buffer);
谢谢,我选择了你的第二个解决方案,它完美的工作!顺便说一下,你能解释一下它为什么会泄漏吗? – b1onic
函数function_something你正在使用alloc/init所以保留计数是1在该字符串,它永远不会被释放。 – aLevelOfIndirection