Justin Bollinger
Justin Bollinger

Reputation: 11

No visible @interface in my main

i can not figure out why I am getting the error No visible @interface for 'StockHoldings' declares the slector

I have googled it and looked thru here and I am still confused could some one point me in the right direction. Thank you.

StockHoldings.h

#import <Foundation/Foundation.h>

@interface StockHoldings : NSObject
{
    //three instance varibles
    float purchaseSharePrices;
    float currentSharePrices;
    int numberOfShares;
}

@property float purchaseSharePrices;
@property float currentSharePrices;
@property int numbeOfShares;

-(float)costInDollars; //purchaseSharePrice * numberOfShares
-(float)valueOfShares; //currentSharePrice * numberOfShares

StockHoldings.m

#import "StockHoldings.h"

@implementation StockHoldings

@synthesize purchaseSharePrices, currentSharePrices, numbeOfShares;

-(float) costInDollars
{
    return ([self purchaseSharePrices] * [self numbeOfShares]);
}

-(float) valueOfShares
{
    return ([self currentSharePrices] * [self numbeOfShares]);
}



@end

main.m

#import <Foundation/Foundation.h>
#import "StockHoldings.h"
int main(int argc, const char * argv[])
{

    @autoreleasepool {

        NSLog(@"Hello\n");

        StockHoldings *stock1 = [[StockHoldings alloc]init];
        [stock1 currentSharePrices:1.0];
        [stock1 purchaseSharePrices:2.0];
        [stock1 numbeOfShares:3];






    }
    return 0;
}

Upvotes: 0

Views: 56

Answers (2)

GoodSp33d
GoodSp33d

Reputation: 6282

You are not using the setters properly. For a @property (weak) id data once synthesized the setter method would be like [self setData:@"foo_bar"]. And getter method will be like [self data] The default name for a setter method is set<Property>

So in your case :

[stock1 setCurrentSharePrices:1.0];
[stock1 setPurchaseSharePrices:2.0];
[stock1 setNumbeOfShares:3];

Upvotes: 0

zneak
zneak

Reputation: 138171

The setter method name for properties is set[PropertyName], so your code should probably read like this:

StockHoldings *stock1 = [[StockHoldings alloc]init];
[stock1 setCurrentSharePrices:1.0];
[stock1 setPurchaseSharePrices:2.0];
[stock1 setNumbeOfShares:3];

At your preference, you may also want to use the dot syntax instead:

StockHoldings *stock1 = [[StockHoldings alloc]init];
stock1.currentSharePrices = 1.0;
stock1.purchaseSharePrices = 2.0;
stock1.numbeOfShares = 3;

And finally, you may want to fix that numbeOfShares typo (missing an R for "number").

Upvotes: 4

Related Questions