• 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: Simple messages problem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Simple messages problem


  • Subject: Re: Simple messages problem
  • From: "K. Darcy Otto" <email@hidden>
  • Date: Thu, 20 Mar 2008 18:32:08 -0700

Thanks for your help; that change did clear up the warning. I want to make sure I understand your explanation though: How is [self.sequent objectAtIndex:lineCount-1] of type "id" as opposed to of type "DeductionLine" (since self.sequent is an NSArray of DeductionLine objects)? Is it that at compilation time, the compiler does not know what sort of object [self.sequent objectAtIndex:lineCount-1] is - but at runtime it turns out to be of type DeductionLine and so that's why everything runs smoothly? But when there is the explicit cast accomplished by (DeductionLine *), the compiler then knows what sort of object [self.sequent objectAtIndex:lineCount-1] is?

When you say the compiler doesn't know which "justification" is going to apply - I take it this is because the Justification object has a justification method. How is it confused, since the class name begins with a capital, and the method begins with a miniscule? Thanks again.

On 20-Mar-08, at 4:16 PM, Quincey Morris wrote:


On Mar 20, 2008, at 15:25, K. Darcy Otto wrote:

So, I seem to be having a problem with the following code, and I think I've traced it to how the messages are nested; but I cannot seem to solve it. Consider the following code, which works without warnings (self.sequent is an NSArray):

DeductionLine *dl1 = [self.sequent objectAtIndex:lineCount-1];
Justification *j1 = [dl1 justification];
NSString *rule1 = [j1 rule];

But the following line generates a warning: NSString may not respond to -rule.


NSString *rule2 = [[[self.sequent objectAtIndex:lineCount-1] justification] rule];

I'm confused about the warning, because [[self.sequent objectAtIndex:lineCount-1] justification] returns type Justification, not NSString. Both examples compile and work; but the warning is in the second case only. Why, and how can I get rid of the warning? Any help would be appreciated. (I think I've included everything necessary to diagnose the problem; please let me know if I haven't; all of this is under Objective-C 2.0 with @synthesize sequent in DeductionLine.)

It sure looks like the compiler is complaining about the wrong thing.

The real problem is that [self.sequent objectAtIndex:lineCount-1] is of type 'id' and the compiler doesn't know which 'justification' is going to apply to it, so it doesn't know the return type of that, so it doesn't know the type of object that 'rule' is being sent to. If you want to write it in one line, you need:

NSString *rule2 = [[(DeductionLine *)[self.sequent objectAtIndex:lineCount-1] justification] rule];

to get rid of the warning.

_______________________________________________

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: Simple messages problem
      • From: Jack Repenning <email@hidden>
References: 
 >Simple messages problem (From: "K. Darcy Otto" <email@hidden>)
 >Re: Simple messages problem (From: Quincey Morris <email@hidden>)

  • Prev by Date: Creating custom sheets
  • Next by Date: Re: Simple messages problem
  • Previous by thread: Re: Simple messages problem
  • Next by thread: Re: Simple messages problem
  • Index(es):
    • Date
    • Thread