我有一個問題,設置一個傳遞的指針爲零。當我通過GDB運行下面的代碼時,我發現傳入的變量「string」在被調用的函數中本地設置爲nil,但在調用的範圍內它仍然指向原始的內存地址。我想解決這個問題,將涉及的參考和值訪問運營商的組合,我只是不夠好,在基本面推測這一個:)Objective-C:設置傳遞指針爲零
#import "AppDelegate.h"
@interface AppDelegate()
+(void)releaseAndNullify:(id)input;
@end
@implementation AppDelegate
@synthesize window;
-(void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
NSString *string = [NSString string];
[AppDelegate releaseAndNullify:string];
}
+(void)releaseAndNullify:(id)input
{
if (input)
{
[input release];
input = nil;
}
}
-(void)dealloc
{
[window release];
[super dealloc];
}
@end
嗨可能這已經被問[這裏](http://stackoverflow.com/questions/6219821/objective-c-method-to -nullify-object)雖然這不是你描述的 – 2011-12-31 14:55:40
謝謝,我沒有看到這個鏈接:) – banDedo 2011-12-31 14:59:39
你到底想要完成什麼? – 2011-12-31 16:40:33