每日一练:OC中的对象概念-堆的内存管理

本文通过一个简单的Objective-C程序示例介绍了如何创建和操作日期对象。包括获取当前时间、创建新的日期实例、对象复制及销毁的过程。展示了NSDate类的基本使用方法。

#import <Foundation/Foundation.h>


int main(int argc, const char * argv[]) {

    @autoreleasepool {

        // insert code here...

//        NSLog(@"Hello, World!");

        NSDate *currentTime = nil;

        NSLog(@"Current Time is %p", currentTime);

        

        NSDate *newDate = [NSDate date];

        NSLog(@"The new date is %p \n", newDate);

        //复制到新的对象

        NSDate *startDate = newDate;

        NSLog(@"The start date is %p \n", startDate);

        

        sleep(5);

        //重置成新的对象

        newDate = [NSDate date];

        NSLog(@"The latest date is now changed to %p \n", newDate);

        

        //销毁对象

        newDate = nil;

        NSLog(@"Now, the new date had been updated to %p \n", newDate);

        

    }

    return 0;

}

Result:

2018-03-10 21:56:58.704032+0800 TOCObjectivea[52371:13638298] Current Time is 0x0

2018-03-10 21:56:58.704302+0800 TOCObjectivea[52371:13638298] The new date is 0x1007119a0

2018-03-10 21:56:58.704330+0800 TOCObjectivea[52371:13638298] The start date is 0x1007119a0

2018-03-10 21:57:03.707665+0800 TOCObjectivea[52371:13638298] The latest date is now changed to 0x10070ca10

2018-03-10 21:57:03.708026+0800 TOCObjectivea[52371:13638298] Now, the new date had been updated to 0x0

Program ended with exit code: 0

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值