我是Objective C的新手。我在理解init()方法時遇到了問題。我已經在Apple網站上閱讀了這兩行代碼:目標C中需要init()
NSObject類中定義的init()方法沒有初始化;它只是返回自我。 (https://developer.apple.com/reference/objectivec/nsobject/1418641-init)
您必須使用init ...方法來完成初始化過程。 (https://developer.apple.com/reference/objectivec/nsobject/1571958-alloc)
如果「它沒有初始化」,我是否需要調用init()來初始化對象?爲什麼?
是的,你總是在'alloc'後面調用'init'方法。爲什麼?那麼,如果沒有其他原因,因爲他們非常一致,並一再告訴我們我們必須這樣做。請參閱[使用對象](https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/WorkingwithObjects/WorkingwithObjects.html#//apple_ref/doc/uid/TP40011210-CH4-SW7)if你正在尋找更多的參考。 – Rob