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