2013-04-08 26 views
-1

我想知道如何從NSObjectClass中調用返回NSMutableArray的方法,並保存將MutableArray返回到調用類中的NSMutableArray。如何將方法返回的NSMutableArray傳遞給NSMutableArray

有效,這是它的外觀

NSObject類有返回值的方法

- (NSMutableArray *)myMethod { 
    // do some stuff 

    return myMutableArray 
} 

調用此方法劑量初始化的一切讓我可以用myMethod的方法,但是什麼類我uncertian的是如何得到返回myMutableArray成MutableArray在這個類...

是它像

TheNameOfTheNSObjectClass *myObjClass = [[TheNameOfTheObjectClass alloc] init]; 
anotherMutableArray = [myObjClass myMethod]; 

因爲多數民衆贊成什麼,我此刻的嘗試,我得到一個警告

不兼容的指針類型分配給「的NSMutableArray * __強」由「TheNameOfTheNSObjectClass *」

任何幫助,將不勝感激。

+0

我認爲需要更多信息。你可以添加'TheNameOfTheNSObjectClass'接口嗎(elide未引用的方法)和'anotherMutableArray'的聲明嗎? 「你是什麼意思」到「NSMutableArray'」?你想複製返回的數組還是隻引用它? – CRD 2013-04-08 20:05:12

+0

你將不得不發佈更多的代碼,你使用ARC?這兩個NSMutableArray是如何定義的? – HackyStack 2013-04-08 20:05:51

+1

我認爲你的第一步應該是學習編程,特別是指針,對象和命令程序的概念。 – 2013-04-08 20:14:28

回答

2

如果你有一個像上一個名爲Baginator類以下的方法:

- (NSMutableArray *) mutableDoggyBags; 

而且你要調用那麼方法:

Baginator *b = [Baginator new]; 
NSMutableArray *bags; 

bags = [b mutableDoggyBags]; 

解析的問題,這聽起來像等價mutableDoggyBags被聲明爲返回除可變數組以外的內容。

特別是,如果這條線的賦值產生錯誤:

anotherMutableArray = [myObjClass myMethod]; 

然後,必須滿足以下條件:

• `myMethod` is not returning the same type as the type of `anotherMutableArray`. 

對你來說,這聽起來像myMethod被聲明爲返回TheNameOfTheNSObjectClass的實例。 I.e .:

- (TheNameOfTheNSObjectClass*) myMethod; 
+0

我已經解決了它,你是正確的初始情況下,它返回TheNameOfTheNSObjectClass,我關閉了應用程序打開它,然後用乾淨的構建清理它,它的工作! WTF – HurkNburkS 2013-04-08 22:32:23

相關問題