• 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: Encoding a Custom Object which has a CALayer instance Variable (newbie Question)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Encoding a Custom Object which has a CALayer instance Variable (newbie Question)


  • Subject: Re: Encoding a Custom Object which has a CALayer instance Variable (newbie Question)
  • From: Gustavo Pizano <email@hidden>
  • Date: Sat, 13 Dec 2008 11:02:53 +0100

Hi, I tried to encode the CAlayer, but when decoding, all the info of the layer its lost.
dunno what happened, the other info of the object it's good.


G


On 13.12.2008, at 6:16, Michael Ash wrote:

On Fri, Dec 12, 2008 at 3:43 PM, Gustavo Pizano
<email@hidden> wrote:
Hello. I want to send the following an object in a drag-n-drop operation, so
I need to transform it to a NSData


so I have this object

@interface Ship : NSObject <NSCoding> {

      int size;
      int impacts;
      ShipLocation * location;
      CALayer * shipImageLayer;

}

now, I was reading that I must implement <NSCoding> and implement the
-(id)initWithCoder:(NSCoder *)coder and -(void)encodeWithCoder: (NSCoder
*)coder methods, so far so good,
then I can use the encodeObject: forKey method of NSCoder class. so I will
have the following


-(id)initWithCoder:(NSCoder *)coder
{
      [coder encodeInt:size forKey:@"size"];
      [coder encodeInt:impacts forKey:@"impacts"];


}

but after I dunno how to code the location and the shipImageLayer? I guess
ShipLocation should implement <NSCoding> also and encode its attributes,
but in shipLocation there is also a CALayer, so I still have the question on
how to do it with a CALayer.

When you get to an object, you can simply encode it using [coder encodeObject:obj forKey:@"key"]. Of course obj must implement NSCoding as well, otherwise this will not work. For your own classes, you'll need to implement NSCoding for everything that will get encoded. CALayer already implements NSCoding so there's nothing tricky for that one.

Mike
_______________________________________________

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

_______________________________________________

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


  • Follow-Ups:
    • Re: Encoding a Custom Object which has a CALayer instance Variable (newbie Question)
      • From: "Michael Ash" <email@hidden>
References: 
 >Encoding a Custom Object which has a CALayer instance Variable (newbie Question) (From: Gustavo Pizano <email@hidden>)
 >Re: Encoding a Custom Object which has a CALayer instance Variable (newbie Question) (From: "Michael Ash" <email@hidden>)

  • Prev by Date: Re: Programmatically constructing list of variable arguments? [Bad Post last one]
  • Next by Date: Re: open package installer in bundle resources directory not working
  • Previous by thread: Re: Encoding a Custom Object which has a CALayer instance Variable (newbie Question)
  • Next by thread: Re: Encoding a Custom Object which has a CALayer instance Variable (newbie Question)
  • Index(es):
    • Date
    • Thread