Copying an NSDate (wanting independent objects)

前端 未结 2 1448
自闭症患者
自闭症患者 2021-02-20 12:04

NSDate conforms to NSCopying protocol. According to the documentation for NSCopying protocol:

a copy must be a functionally independent object with values ident         


        
2条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-20 12:33

    copy does not guarantee different object pointer. “Functionally independent” means that changes to the original object will not be reflected in the copy, and thus for immutable objects copy may work as retain (I don't know if this is guaranteed though, probably not).

    Try date2 = [[NSDate alloc] initWithTimeInterval:0 sinceDate:date1].

提交回复
热议问题