tags:

views:

390

answers:

1

I can't get this to work:

 NSString *string = @"!#€%&/()*^*_:;;:;_poawolwasnndaw";
 NSData *stringData = [string dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:NO];

stringData will be nil. Why?

+2  A: 

According to the documentation, setting allowLossyConversion:NO yields the following potential behavior:

Returns nil if flag is NO and the receiver can't be converted without losing some information (such as accents or case).

In this case, the Euro symbol above has no ASCII equivalent, so the entire result will come back nil.

fbrereto