-2

I'm trying to convert NSString to NSArray of characters by I haven't found a way to do it.

Here is my code:

NSString *one = @"abc";
const char *charOne= [one UTF8String];

But if I try to convert NSArray:

 NSArray *arrayOne = [[NSArray alloc] initWithArray:(NSArray*)charOne];

I get this error: Cast of non-Objective-C pointer type const char * to NSArray is disallowed in ARC

My question to guys, how can I can convert NSString to NSArray of characters?

I'll really appreciate your help

rmaddy
  • 307,833
  • 40
  • 508
  • 550
user2924482
  • 7,520
  • 20
  • 78
  • 152

1 Answers1

0

try this

NSMutableArray *letterArray = [NSMutableArray array];
NSString *letters = @"ABCDEFक्";
[letters enumerateSubstringsInRange:NSMakeRange(0, [letters length]) 
                                    options:(NSStringEnumerationByComposedCharacterSequences) 
                                 usingBlock:^(NSString *substring, NSRange substringRange, NSRange enclosingRange, BOOL *stop) {
            [letterArray addObject:substring];
        }];

from : NSString to NSArray

Community
  • 1
  • 1
Axel
  • 758
  • 6
  • 19