• 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: Best Way to Handle Properties?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Best Way to Handle Properties?


  • Subject: Re: Best Way to Handle Properties?
  • From: Jason Coco <email@hidden>
  • Date: Tue, 19 Aug 2008 14:24:26 -0400


On Aug 19, 2008, at 13:02 , Dave wrote:

My specific questions are:

Is the NSString allocation and initWithCharacters code the best way to do this? If so, what would the setter look like in this case? If not what is a better way of doing it?

Hey Dave,

I don't think that initWithCharacters is what you want... that expects an array of unichar characters, which isn't what you said you had. Since you're doing the encoding in your other function, and you know what it is, just use the initWithBytes function and the specific encoding. For example (assuming your byte array was in UTF-16BE:

char *buf = /* initialized and filled somewhere else */
size_t buf_len = /* set somewhere else */

NSString *myString = [[NSString alloc] initWithBytes:buf length:buf_len encoding:NSUTF16BigEndianStringEncoding];

Just remember, the length is the actual number of bytes (including the 0x00 bytes in the array), not the number of code points or the number of characters.

/Jason

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

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: 
 >Best Way to Handle Properties? (From: Dave <email@hidden>)

  • Prev by Date: Re: Deploying project as backward compatible
  • Next by Date: Re: How to reference a NSDocument from a NSView?
  • Previous by thread: Best Way to Handle Properties?
  • Next by thread: Re: Best Way to Handle Properties?
  • Index(es):
    • Date
    • Thread