• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: convert password from SecKeychainFindGenericPassword to NSString
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: convert password from SecKeychainFindGenericPassword to NSString


  • Subject: Re: convert password from SecKeychainFindGenericPassword to NSString
  • From: Kyle Sluder <email@hidden>
  • Date: Sun, 31 Jan 2010 18:49:03 -0800

On Sun, Jan 31, 2010 at 6:28 PM, Stuart Malin <email@hidden> wrote:
> If I use +dataWithBytes:length: then I need to specify a length 1 greater, and that additional byte must be set to 0 (to null terminate the string). So, I could use NSMutableData, then -resetBytesInRange: to zero out the last byte, which requires creating an NSRange struct, and that all seems heavier than just using the C code.  But then, the processor is fast, and this is code that is run rarely, so optimizing isn't important.  I guess it is just a question of style...

This is not true. The data you provide does not need to be a
null-terminated C string. Though I'd use Stephen's approach because
you don't have to create a wrapper data object. Proof that it works:

#import <Foundation/Foundation.h>

int main(int argc, char **argv) {
  char p[5] = {'H', 'e', 'l', 'l', 'o'};
  NSString *s = [[NSString alloc] initWithBytes:p
    length:5 encoding:NSUTF8StringEncoding];
  NSLog(@"s = %@", s);
  [s release];
  return 0;
}

--Kyle Sluder
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >convert password from SecKeychainFindGenericPassword to NSString (From: Stuart Malin <email@hidden>)
 >Re: convert password from SecKeychainFindGenericPassword to NSString (From: Kyle Sluder <email@hidden>)
 >Re: convert password from SecKeychainFindGenericPassword to NSString (From: Stuart Malin <email@hidden>)

  • Prev by Date: Re: sine wave
  • Next by Date: Re: convert password from SecKeychainFindGenericPassword to NSString
  • Previous by thread: Re: convert password from SecKeychainFindGenericPassword to NSString
  • Next by thread: Re: convert password from SecKeychainFindGenericPassword to NSString
  • Index(es):
    • Date
    • Thread