Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Warning: type 'id <NSTextAttachmentCell>' does not conform to the 'NSCopying' protocol



id<NSTextAttachmentCell> refers to a protocol named NSTextAttachmentCell, which does not conform to NSCopying.
http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Protocols/NSTextAttachmentCell_Protocol/Reference/Reference.html


NSTextAttachmentCell* refers to a class named NSTextAttachmentCell, which does conform to NSCopying (by virtue of being an NSCell subclass).
http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSTextAttachmentCell_Class/Reference/Reference.html
http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSCell_Class/Reference/NSCell.html


So the compiler is warning you that you are effectively casting from a type that does not conform to NSCopying, to a type that does conform to NSCopying.

It's hard to say whether this is a problem or not. If the object really is of the NSTextAttachmentCell class, there is probably nothing to worry about.


Stefan Haller wrote:
I have a piece of code that loops over all attachments in a text view
and messes with their cells.

I'm getting this compiler warning that I can't explain:

  warning: type 'id <NSTextAttachmentCell>' does not
           conform to the 'NSCopying' protocol

Why should it?  There's no 'copy' in my code.  The warning goes away if
I change the marked line to this:

  id <NSTextAttachmentCell> cell_id = [attachment attachmentCell];
  NSTextAttachmentCell *cell = (NSTextAttachmentCell*) cell_id;

Can anybody explain this to me please?

Best,
   Stefan



  unsigned end = [textStorage length];
  NSRange effectiveRange = { 0, 0 };
  while (NSMaxRange(effectiveRange) < end) {
      NSTextAttachment *attachment =
          [textStorage attribute:NSAttachmentAttributeName
                         atIndex:NSMaxRange(effectiveRange)
                  effectiveRange:&effectiveRange];
      if (attachment) {
          NSTextAttachmentCell *cell = [attachment attachmentCell];  // <-- warning here

          /* do stuff with cell */
      }
  }


_______________________________________________

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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden
References: 
 >Warning: type 'id <NSTextAttachmentCell>' does not conform to the 'NSCopying' protocol (From: email@hidden (Stefan Haller))



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.