2013-10-02 28 views
1

下面的代碼ivI'e照片幻燈片的教程遇到我認爲是一些廢棄的代碼。我有一個autorelease ARC錯誤並setDelegate:selfautorelease已棄用,是否有替代方案?

NSXMLParser *photoParser = [[[NSXMLParser alloc] 
           initWithContentsOfURL:[NSURL URLWithString: 
                 @"http://localhost/photos/index.xml"]] autorelease]; 
    [photoParser setDelegate:self]; 
+2

這不是「過時」(這意味着它不會在將來支持)。在使用ARC時,您不需要編寫它(編譯器會在適當的位置放入'retain','release','autorelease'等)。 –

回答

3

警告刪除自動釋放,以便代碼如下所示:

ARC不允許明確的自動釋放呼叫。如果你想要一個對象被釋放,你不需要做任何事情(ARC會處理它)。在某些情況下,你可能要設置一個目標是零(如photoParser =零;)

NSXMLParser *photoParser = [[NSXMLParser alloc] 
           initWithContentsOfURL:[NSURL URLWithString: 
                 @"http://localhost/photos/index.xml"]]; 
[photoParser setDelegate:self]; 
相關問題