क्या एनएसएमयूटेबलएरे को पाने के लिए कोई तरीका है जिससे आप सरणी के अंदर "छेद" प्राप्त कर सकें जहां संगत वस्तुओं के बजाय सरणी के केवल भाग भर गए हों?एनएसएमयूटेबलएरे के सम्मिलित करें ऑब्जेक्ट्स: एन्डेक्स और इंडेक्स सीमाओं से परे
मैं सरणी की शुरुआत में भरे कुछ तत्वों के साथ प्रारंभिक सरणी बनाना चाहता हूं। कुछ समय बाद, मैं 9 नए आइटम डालना चाहता हूं, मेरे वर्तमान अंतिम के तुरंत बाद नहीं, लेकिन सरणी के बीच में किसी बिंदु पर, इस प्रकार सरणी सूची के हिस्सों में एक छेद छोड़ना।
मैंने सोचा कि मैं के साथ ऐसा कर सकता है, लेकिन मैं त्रुटि मिलती है:
NSRangeException', reason: '***
-[NSMutableArray insertObject:atIndex:]: index 28 beyond bounds [0 .. 5]'
कोड:
NSMutableArray *targetArray = [NSMutableArray arrayWithCapacity:100];
- (void)fillInInitially {
// Add the first set of elements to the beginning of the array
for (int i = 0; i < [initialData count]; ++i)
{
[targetArray insertObject:[initialData objectAtIndex:i] atIndex:i];
}
}
- (void)fillInTheBlank:(NSArray *) additions {
// Start adding at index position 28 and current array has 5 items
NSRange range = NSMakeRange(28, [additions count]);
NSIndexSet *indexSet = [NSIndexSet indexSetWithIndexesInRange:range];
// Can't do this when I'm trying to add 9 new items at index 28
// because of the error: index 28 beyond bounds [0 .. 5]
[targetArray insertObjects:additions atIndexes:indexSet];
}
मैं "रिक्त" कि होगा के बाद से छेद में आइटम डालने के लिए नहीं करना चाहता था जब मैं सरणी में कई सौ वस्तुओं को पकड़ सकता हूं तो स्मृति ले लो।
मुझे किसी प्रकार की "स्पैस" सरणी डेटा संरचना की आवश्यकता है।