Stuck Please Help - Can't Add object into Portfolio Instance


#1

I’m having a hard time figuring out why I keep getting "No visible @interface for ‘Portfolio’ declares the selector 'addDomesticStock:'
for the line in main.m file [portfolio addDomesticStock:stock1];
Can someone please help tell me what I did wrong here?
I can’t seem to add an object into the portfolio instance which should add to the portfolio’s array?
Thanks.

main.m
___________
#import <Foundation/Foundation.h>
#import "Portfolio.h"
#import "StockHolding.h"
#import "ForeignStockHolding.h"


int main(int argc, const char * argv[])
{

    @autoreleasepool {
        
        
        //create an instance of portfolio
        Portfolio *portfolio = [[Portfolio alloc] init];
        
        StockHolding *stock1 = [[StockHolding alloc] init];
        StockHolding *stock2 = [[StockHolding alloc] init];
        StockHolding *stock3 = [[StockHolding alloc] init];
        
        [stock1 setPurchaseSharePrice:19.85];
        [stock1 setCurrentSharePrice:26.34];
        [stock1 setNumberOfShares: 150];
        [stock1 setStockID: 1];
        
        [stock2 setPurchaseSharePrice:19.85];
        [stock2 setCurrentSharePrice:26.34];
        [stock2 setNumberOfShares: 150];
        [stock2 setStockID: 2];
        
        [stock3 setPurchaseSharePrice:19.85];
        [stock3 setCurrentSharePrice:26.34];
        [stock3 setNumberOfShares: 150];
        [stock3 setStockID: 3];
        
        ForeignStockHolding *fstock1 = [[ForeignStockHolding alloc] init];
        ForeignStockHolding *fstock2 = [[ForeignStockHolding alloc] init];
        ForeignStockHolding *fstock3 = [[ForeignStockHolding alloc] init];
        
        [fstock1 setPurchaseSharePrice:100.50];
        [fstock1 setCurrentSharePrice:150.50];
        [fstock1 setNumberOfShares:10];
        [fstock1 setCurrentSharePrice:.25];
        [fstock1 setStockID:4];
        
        [fstock2 setPurchaseSharePrice:87.33];
        [fstock2 setCurrentSharePrice:93.50];
        [fstock2 setNumberOfShares:250];
        [fstock2 setConversionRate:.382];
        [fstock1 setStockID:5];
        
        [fstock3 setPurchaseSharePrice:1.00];
        [fstock3 setCurrentSharePrice:2.00];
        [fstock3 setNumberOfShares:100];
        [fstock3 setConversionRate:.50];
        [fstock1 setStockID:6];
        
        NSMutableArray *dstockarray = [NSMutableArray array];
        [dstockarray addObject:stock1];
        [dstockarray addObject:stock2];
        [dstockarray addObject:stock3];
        
        NSMutableArray *fstockarray = [NSMutableArray array];
        [fstockarray addObject:fstock1];
        [fstockarray addObject:fstock2];
        [fstockarray addObject:fstock3];
        
        for (StockHolding *a in dstockarray)
        {
            NSLog(@"\n.The purchase share price is $%.2f.\n.The current share price is $%.2f.\n.The number of shares purchased is %d.\n.The total cost is $%.2f.\n.The total value is $%.2f.\n\n", [a purchaseSharePrice], [a currentSharePrice], [a numberOfShares], [a costInDollarsDomestic], [a valueInDollarsDomestic]);
        }
        
        for (ForeignStockHolding *b in fstockarray)
        {
            NSLog(@"\n.The purchase share price is $%.2f.\n.The current share price is $%.2f.\n.The number of shares purchased is %d.\n.The total cost is $%.2f.\n.The total value is $%.2f.\n\n", [b purchaseSharePrice], [b currentSharePrice], [b numberOfShares], [b costInDollarsForeign], [b valueInDollarsForeign]);
        }

        
        //Add stock objects to portfolio object which in the background is an array
        [portfolio addDomesticStock:stock1];
        
    }
    return 0;
}

Portfolio.h
_____________
#import "StockHolding.h"
#import "ForeignStockHolding.h"

@interface Portfolio : StockHolding

{
    NSMutableArray *domesticstockarray;
    NSMutableArray *foreignstockarray;
}


-(float) portfolioValue;

-(void)addDomesticStock:(StockHolding *)DStock;

-(void)addForeignStock:(ForeignStockHolding *)FStock;

@end
portfolio.m
____________

#import "Portfolio.h"
#import "StockHolding.h"
#import "ForeignStockHolding.h"

@implementation Portfolio


-(void)addDomesticStock:(StockHolding *)DStock
{
  //Is the domesticstockarray empty?
    if(!domesticstockarray) {
    
        //Create the array called domesticstockarray which was already declared in portfolio.h file
        domesticstockarray = [[NSMutableArray alloc] init];
        
    }
    [domesticstockarray addObject:DStock];
}


-(void)addForeignStock:(ForeignStockHolding *)FStock
{
    //Is the foreignstockarray empty?
    if (!foreignstockarray) {
        
        //Create the array called foreignstockarray which was already declared in portfolio.h file
        foreignstockarray = [[NSMutableArray alloc] init];
    
    }
    [foreignstockarray addObject:FStock];
}


-(float) portfolioValue
{
    float sum = 0.0;
    for (int i = 0; i < [domesticstockarray count]; i++) {
        sum += [[domesticstockarray objectAtIndex:i] valueInDollarsDomestic];
    }
    for (int i=0; i < [foreignstockarray count]; i++) {
        sum += [[foreignstockarray objectAtIndex:i] valueInDollarsForeign];
    }
    return sum;
}

@end
StockHolding.h
_______________

#import <Foundation/Foundation.h>

@interface StockHolding : NSObject
{
    float purchaseSharePrice;
    float currentSharePrice;
    int numberOfShares;
    int stockID;
}

@property float purchaseSharePrice, currentSharePrice;
@property int numberOfShares, stockID;

- (float)costInDollarsDomestic;
- (float)valueInDollarsDomestic;


@end
StockHolding.m
__________________

#import "StockHolding.h"

@implementation StockHolding

@synthesize purchaseSharePrice, currentSharePrice, numberOfShares, stockID;


-(float)costInDollarsDomestic
{
    return purchaseSharePrice * numberOfShares;
}

-(float)valueInDollarsDomestic
{
    return currentSharePrice * numberOfShares;
}


@end
ForeignStockHolding.h
______________________

#import "StockHolding.h"

@interface ForeignStockHolding : StockHolding

{
    float conversionRate;
}


@property float conversionRate;

-(float)costInDollarsForeign;
-(float)valueInDollarsForeign;

@end
ForeignStockHolding.m
____________________


#import "ForeignStockHolding.h"

@implementation ForeignStockHolding

@synthesize conversionRate;


-(float)costInDollarsForeign
{
    float xcostusa = [super costInDollarsDomestic];
    return xcostusa * conversionRate;
}

-(float)valueInDollarsForeign
{
    float xvalueusa = [super valueInDollarsDomestic];
    return xvalueusa * conversionRate;
}



@end

#2

I created a new project and reentered all code and it works now without the error.
I realized what I did wrong. I made the portfolio class initially a subclass of NSObject and when I realized others have created it as a subclass of StockHolding, I decided to delete the file from the project and create a new portfolio class file That screwed up things so when I press build it threw that no visible interface error.

What happens if I’m working on a big project and I accidentally created a wrong class that I want to delete or assigned it the wrong subclass to? How do I edit or how do I delete it without affecting other things, other files, or building and compiling? Please advise?

Is there a way also to copy projects and renaming them without messing up the files inside?