OC中遍历数组操作的结果为什么是一串地址?

新手上路,请多包涵

头文件

#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对象的值,该如何操作呢?目前运行结果是返回了一个地址。。初学者不太懂

阅读 2k
1 个回答

因为打印的是指针,如果你想要打印更详细的信息
你可以重写LSTStockHolding 类的description方法,如下
教程

- (NSString *)description{
    
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进