2014-09-02 26 views
0

我寫這段代碼:的iOS指向指針的NSMutableDictionary

- (void) addKey:(NSString *)key inMessage:(DEMessage *)message to:(NSMutableDictionary * __autoreleasing *)to 
{ 
    if ([message getPropertyByPath:key]) { 
     [*to setObject:@([[message getPropertyValue:key] floatValue]) forKey:key]; 
    } 
} 

這一點我通過撥打:

NSMutableDictionary *statistics = [NSMutableDictionary new]; 
[self addKey:@"Yellow" inMessage:message to:&statistics]; 
[self addKey:@"Red" inMessage:message to:&statistics]; 
[self addKey:@"Matches" inMessage:message to:&statistics]; 
[self addKey:@"Goals" inMessage:message to:&statistics]; 
[self addKey:@"GoalsPerMatch" inMessage:message to:&statistics]; 
[self addKey:@"Faults" inMessage:message to:&statistics]; 
[self addKey:@"Expelled" inMessage:message to:&statistics]; 
_statistics = [statistics copy]; 

我寫的就是這麼刪除重複代碼的方法。唯一的問題是,當我使用開發證書構建它時,一切都很好,但是當我使用生產/臨時證書時,它會在這件事上崩潰。

我收到的錯誤是段錯誤11.對我說,我正在使用不是我的內存。我沒有得到這個...

所以,問題是:「爲什麼在生產/特設證明我的程序崩潰,爲什麼是我的代碼不正確提前

感謝,

+4

問題是:你爲什麼傳遞一個指針指針? :0 – 2014-09-02 07:18:18

+0

另外,那是什麼'@([[message getPropertyValue:key] floatValue])'?這是完全多餘的,不可讀和不必要的。 – 2014-09-02 07:19:48

+0

@TheParamagneticCroissant有些人使用這個庫並不是難以理解的,這就是問題的焦點 – Haagenti 2014-09-02 07:23:48

回答

1

?我認爲這是使用(NSMutableDictionary * __autoreleasing *)參數這是沒有必要的,我猜它造成NSMutableDictionary被overreleased這將更好的寫法如下:。

NSMutableDictionary* stats = [NSMutableDictionary new]; 
NSArray* keys = @[@"Yellow", @"Red", @"Matches"]; //etc. 
for(NSString* k in keys){ 
    NSNumber* value = [message getPropertyByPath:k]; 
    if (value) { 
     [stats setObject:value forKey:k]; 
    } 
} 
_statistics = [statistics copy]; 

它可能由該事觸發差異賭注調試和發佈版本。

+0

使用指針指針反而不正確。我解決了這個問題。而你關於被不同事物觸發的說法很可能是真的。但我在哪裏可以找到這個?所以我可以看到生產和發展之間有什麼不同 – Haagenti 2014-09-02 08:08:46