objective-c - OC中遍历数组操作的结果为什么是一串地址?
过去多啦不再A梦
过去多啦不再A梦 2017-05-02 09:29:55
0
1
494

头文件

#import "LSTStockHolding.h"

@implementation LSTStockHolding
-(float)costInDollars
{
    float c = [self purchaseSharePrice];
    return c*[self numberOfShares];
}
-(float)valueInDollars
{
    return [self currentSharePrice]*[self numberOfShares];
    

main函数

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;

运行结果如图
2016-09-08 15:36:20.988 20章[863:97992] The cid is:24.00,the vid is:30.00.
2016-09-08 15:36:20.990 20章[863:97992] Here is a list:<LSTStockHolding: 0x1001055d0>
Program ended with exit code: 0

我想通过遍历数组的操作,枚举数组list的对象并且输出LSTStockHolding对象的值,该如何操作呢?目前运行结果是返回了一个地址。。初学者不太懂

过去多啦不再A梦
过去多啦不再A梦

reply all(1)
刘奇

Because what is printed is a pointer, if you want to print more detailed information
you can rewrite the LSTStockHolding 类的description method, as shown below
tutorial

- (NSString *)description{
    
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template