copyWithZone being called

So i have 2 Objects.

   NSString *name;
   Book *book;

   NSString *title
   NSString *author;

The properties are all set up as (readwrite,copy)

   Library *library;
   Book *book;

   library = [[Library alloc] init];
   book = [[Book alloc]init];

  //The fallowing all works = @"Library Name";
  book.title = @"book Title"; = @"book author";

 //The fallowing crashes my app = book;

How can I encapsulate Book inside of the library object?

The debugger gives me the fallowing error.

[library copyWithZone:]: unrecognized selector


The -copyWithZone: selector is being called because you're assigning an object to a property that is marked as (copy). Marking it as (copy) tells the compiler to create a setter on your behalf that tries to make a copy of the object being assigned.

You either need to mark your properties as (readwrite, retain), so that you retain the existing instance of Book instead of making a copy, or you need to implement the NSCopying protocol for your Book class. Here's Apple's documentation on NSCopying:

Whether you change the property attributes or adopt the NSCopying protocol depends on whether you truly need to copy the object being assigned (usually only necessary when the object being assigned is modifiable and may be changed by the caller or someone else), or can get away with just retaining a reference to the existing object (considered to be the normal case).

Need Your Help

Messages on command prompt

batch-file cmd

I want to show the result of my function as a pop up message.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.