RE "Property ConversionRate not found..."


#1

Hi - this is my very first post. I have been playing with this thing for hours. All of my attempts fail and I would appreciate some help.

Here is my Main Program:

    StockHolding *sh1 = [ForeignStockHolding new];
    StockHolding *sh2 = [ForeignStockHolding new];
    StockHolding *sh3 = [ForeignStockHolding new];
    
    sh1.PurchaseSharePrice=1.8;
    sh1.CurrentSharePrice=3.6;
    sh1.NumberOfShares=1000;
    sh1.ConversionRate=1.6;

This last instruction gives me the error “Property ‘ConversionRate’ not found on object of type Stockholding *”

Here is my ForeignStockHolding.h file:

#import <Foundation/Foundation.h>
#import “StockHolding.h”
@interface ForeignStockHolding : StockHolding
{
float conversionRate;
}
@property float conversionRate;
@end


#2

[quote]sh1.ConversionRate=1.6; ... @interface ForeignStockHolding : StockHolding { float conversionRate; } @property float conversionRate; @end[/quote]
The name of a property used in an expression should match the name in the corresponding declaration.

Therefore, the expresion sh1.[color=#FF0000]ConversionRate[/color] should be sh1.conversionRate.

Case matters: ConversionRate is not the same as conversionRate.


#3

That didn’t solve my problem - I still get the same error.

The reason I went with the Uppercase is because the program works with these properties defined as shown (lowercase), yet referenced in main using Uppercase. If this works with properties in Stockholding, why not with the property in ForeignStockHolding?

#import <Foundation/Foundation.h>

@interface StockHolding : NSObject
@property float purchaseSharePrice;
@property float currentSharePrice;
@property int numberOfShares;

  • (float) costInDollars;
  • (float) valueInDollars;

@end


#4

The Objective-C language is case sensitive: That is, FooBar and fooBar are not the same name.

Therefore, when referencing something by name you must use the exact name used in the declaration.


#5

Well I found my error and it was NOT the uppercase/lowercase name problem. Here’s what I finally got to work.

I had initially defined the three *sh declarations as StockHolding rather than ForeignStockHolding. When I changed as below it worked.

To test your reply, I found that both Uppercase and Lowercase work in the “set”. Don’t ask me why - this is Xcode…

    ForeignStockHolding *sh1 = [ForeignStockHolding new];
    ForeignStockHolding *sh2 = [ForeignStockHolding new];
    ForeignStockHolding *sh3 = [ForeignStockHolding new];
    
    sh1.PurchaseSharePrice=1.8;
    sh1.CurrentSharePrice=3.6;
    sh1.NumberOfShares=1000;
    sh1.ConversionRate=1.6;
    
    sh2.purchaseSharePrice=7.9;
    sh2.currentSharePrice=3.6;
    sh2.numberOfShares=1000;
    sh2.conversionRate=1.6;

#6

In the future though, I think you may want to follow the suggested rule of thumb when it comes to making sure your declaring method and referencing method are exactly the same. I think the reason Xcode isn’t logging an error is because it understands what your referring to. Similar to when we didn’t place the asterisk for a pointer in the right place i.e. NSArray* pointer = @[…]; here the * should be placed right before “pointer”, as in *pointer. However, Xcode knows what your referring to so it’ll do it for you. It’s best practice to make it explicit but then again it’s your choice…