頭檔
#import "LSTStockHolding.h"
@implementation LSTStockHolding
-(float)costInDollars
{
float c = [self purchaseSharePrice];
return c*[self numberOfShares];
}
-(float)valueInDollars
{
return [self currentSharePrice]*[self numberOfShares];
main函數(shù)
int main(int argc, const char * argv[]) {
@autoreleasepool {
// insert code here...
LSTStockHolding *China = [[LSTStockHolding alloc]init];
China.purchaseSharePrice = 4.0;
China.currentSharePrice = 5.0;
China.numberOfShares = 6.0;
float cid =[China costInDollars];
float vid =[China valueInDollars];
NSLog(@"The cid is:%.2f,the vid is:%.2f.",cid,vid);
NSArray *list = @[China];
for(NSString *s in list)
{
NSLog(@"Here is a list:%@",s);
}
}
return 0;
運(yùn)行結(jié)果如圖
2016-09-08 15:36:20.988 20章[863:97992] The cid is:24.00,the vid is:30.00.
2016-24.00,the vid is:30.00.
2016-09-08 15:396963:3966-09-6863:3966990963:39663:39663:396963:39669:39669:396963:396969:3969393993999399399393933位[3933999939分話(huà)[ :97992] Here is a list:
我想透過(guò)遍歷數(shù)組的操作,枚舉數(shù)組list的物件並且輸出LSTStockHolding物件的值,該如何操作呢?目前運(yùn)行結(jié)果是回傳了一個(gè)位址。 。初學(xué)者不太懂??
因?yàn)橛∷⒌氖侵羔?如果你想要打印更詳細(xì)的信息
你可以重寫(xiě)LSTStockHolding
類(lèi)的description
方法,如下
教程
- (NSString *)description{
}