-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
  • 314,917
  • 42
  • 532
  • 579
user2924482
  • 8,380
  • 23
  • 89
  • 173

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
  • 768
  • 6
  • 20