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

头文件

#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梦

Antworte allen(1)
刘奇

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

- (NSString *)description{
    
}
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage