1
你如何指向Swift中的指針?在Objective-C中,我有一個函數,我將遞歸調用,以便可以跟蹤遞歸的數量,但我很難理解如何在Swift中實現這一點。Swift函數中指針參數的指針
NSNumber *recursionCount = [NSNumber numberWithInteger:-1];
[self doRecursion:&recursionCount];
- (void)doRecursion:(NSNumber **)recursionCount {
// I'm sure this is a terrible way to increment, but I have limited Objective-C experience
// and this worked, so I moved on after failing to find a decent var++ equivalent :-(
int addThis = (int)i + 1;
*recursionCount = [NSNumber numberWithInt:[*recursionCount intValue] + addThis];
[self doRecursion:recursionCount];
}
在此切割下來的樣品爲這篇文章的過程中,我已經結束了創建一個永無止境的循環,但你上我怎麼記得每次遞歸的價值理念。
有誰知道如何在Swift中做到這一點?謝謝。
感謝。我必須錯過或刪減inout參數部分。我甚至嘗試了AutoreleasingUnsafeMutablePointer和UnsafeMutablePointer ,但那導致我走了一條悲傷的路:) –
2014-09-11 00:10:25