• 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
Save struct to NSDictionary
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Save struct to NSDictionary


  • Subject: Save struct to NSDictionary
  • From: Lorenzo <email@hidden>
  • Date: Thu, 15 Sep 2005 22:55:38 +0200

Hi,
I defined a simple struct like this

typedef struct
{
    float x;
    float y;
    BOOL  on;
}
XVector;

And I have an array of this struct: XVector xVectors[16];
I would like to transform xVectors[16] to a NSData object so I can put it
into a NSDictionary and save it together with the document file.
Actually I transform xVectors to a NSMutableArray then I add this array to
the document dictionary.

- (NSMutableArray*)GetXVector
{
 NSMutableArray         *vArray = [NSMutableArray array];
 NSMutableDictionary    *vDict;

 int i, totVectors = 16;
 for(i = 0; i < 16; i++){
     vDict = [NSMutableDictionary dictionary];
    [vDict setObject:[NSNumber numberWithFloat:xVectors[i].x] forKey:@"x"];
    [vDict setObject:[NSNumber numberWithFloat:xVectors[i].y] forKey:@"y"];
    [vDict setObject:[NSNumber numberWithBool:xVectors[i].on] forKey:@"on"];
    [vArray addObject:vDict ];
  }
  return vArray ;
}

But I find it not so elegant.
I presume there should be a way to transform xVectors to an NSData in one
shot only, then add this NSData to my dictionary I will save to a file.
Do you know how to convert xVectors[16] to a NSData?


Best Regards
--
Lorenzo
email: email@hidden

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Save struct to NSDictionary
      • From: Dustin Voss <email@hidden>
    • Re: Save struct to NSDictionary
      • From: Sherm Pendley <email@hidden>
    • Re: Save struct to NSDictionary
      • From: Steve Christensen <email@hidden>
  • Prev by Date: Re: NSDatePicker / NSDatePickerCell
  • Next by Date: Editable Text fields and borderless windows
  • Previous by thread: Re: Xcode custom new file templates?
  • Next by thread: Re: Save struct to NSDictionary
  • Index(es):
    • Date
    • Thread