Command / Applications / Xcode.app / Contents / Developer / Toolchains / XcodeDefault.xctoolchain / usr / bin / clang失败,退出代码为1
当我尝试运行这些文件时,我收到的错误就像上面那样。
我创建了BNRStockHolding.h和BNRStockHolding.m
这是.h文件 #import
@interface BNRStockHolding : NSObject
//getter and setter
@property (nonatomic, readwrite) float purchaseSharePrice;
@property (nonatomic, readwrite) float currentSharePrice;
@property (nonatomic, readwrite) int numberOfShares;
//method involving calculation
-(float)costInDollars;
-(float)valueInDollars;
@end
这是.m文件
#import "BNRStockHolding.h"
@implementation BNRStockHolding
-(float)costInDollars{
float total=([self purchaseSharePrice]*[self numberOfShares]);
return total;
}
-(float)valueInDollars{
float currenttotal=([self currentSharePrice]*[self numberOfShares]);
return currenttotal;
}
@end
这是代码文件
#import <Foundation/Foundation.h>
#import "BNRStockHolding.h"
#import "BNRStockHolding.m"
int main(int argc, const char * argv[])
{
@autoreleasepool {
//Creating instsances of BNRStockHolding to be stored in an array later
BNRStockHolding *a=[[BNRStockHolding alloc]init];
BNRStockHolding *b=[[BNRStockHolding alloc]init];
BNRStockHolding *c=[[BNRStockHolding alloc]init];
//Storing value of a here
a.purchaseSharePrice=2.30;
a.currentSharePrice=4.50;
a.numberOfShares=40;
//Storing value of b here
b.purchaseSharePrice=12.19;
b.currentSharePrice=10.56;
b.numberOfShares=90;
//Storing value of c here
c.purchaseSharePrice=45.10;
c.currentSharePrice=49.51;
c.numberOfShares=210;
//Creating an instance of NSArray class
NSMutableArray *stockptr=[NSMutableArray array];
//Add instances into the mutable array
[stockptr addObject:a];
[stockptr addObject:b];
[stockptr addObject:c];
//printing value
for (BNRStockHolding* ptr in stockptr){
NSLog(@"1 is %f, 2 is %f, 3 is %d,%f,%f",ptr.purchaseSharePrice,ptr.currentSharePrice,ptr.numberOfShares, [ptr costInDollars],[ptr valueInDollars] );
}
}
return 0;
}
此外,我将.m和.h文件存储在存储main.m文件的文件夹中。我应该在main.m文件上面存储.m和.h一个文件夹吗?希望有人可以帮我解决这个问题。