-2

i'm trying to convert NSArray to NSDictionary using this code that i found in this post: Convert NSArray to NSDictionary

@implementation NSArray (indexKeyedDictionaryExtension)

- (NSDictionary *)indexKeyedDictionary
{
NSUInteger arrayCount = [self count];
id arrayObjects[arrayCount], objectKeys[arrayCount];

[self getObjects:arrayObjects range:NSMakeRange(0UL, arrayCount)];
for(NSUInteger index = 0UL; index < arrayCount; index++) { objectKeys[index] = [NSNumber numberWithUnsignedInteger:index]; }

return([NSDictionary dictionaryWithObjects:arrayObjects forKeys:objectKeys count:arrayCount]);
}

@end

However there is an error in the line of [self get objects:array objects,...],with message: Sending “NSString _strongto parameter of type _unsafe_unretained id* ”change retain/release properties of pointer. I assume this is because an ARC issue, since the post is in 2009. Anyone know how to get rid the issue?thanks..

Community
  • 1
  • 1
user2373192
  • 31
  • 1
  • 5
  • what is [self count] ?? self ?? display it in console by NSLog ? and http://stackoverflow.com/questions/12868603/sending-nsstring-strongto-parameter-of-type-unsafe-unretained-id-change-r –  Aug 19 '13 at 04:34
  • http://pastebin.com/YWYbStxK –  Aug 19 '13 at 04:43
  • 2
    What's the advantage of creating a dictionary where the key is just the index anyway? None that I can see. – trojanfoe Aug 19 '13 at 04:44
  • i try the pastebin link, and still error in this line:[self getObjects:arrayObjects range:NSMakeRange(0UL, arrayCount)]; – user2373192 Aug 19 '13 at 04:48

1 Answers1

0

The solution is almost the same as in the link Sending "NSString *_strong*to parameter of type _unsafe_unretained id* "change retain/release properties of pointer given by Ranju Patel above:

__unsafe_unretained id arrayObjects[arrayCount];
id objectKeys[arrayCount];
[self getObjects:arrayObjects range:NSMakeRange(0UL, arrayCount)];

because getObject:range: is declared as

- (void)getObjects:(id __unsafe_unretained [])objects range:(NSRange)range;

The reason is that ARC cannot manage the lifetime of objects in a plain C array, therefore the objects have to be declared as __unsafe_unretained. This is also explained in "Common Issues While Converting a Project" in the "Transitioning to ARC Release Notes".

Community
  • 1
  • 1
Martin R
  • 529,903
  • 94
  • 1,240
  • 1,382