Compare NSDate for Today or Yesterday

前端 未结 4 1315
-上瘾入骨i
-上瘾入骨i 2020-12-30 10:03

Well I guess this has been asked a thousand times, but for some reason the answeres dont really work or had other problems,....

Anyway here is what I have \"working\

4条回答
  •  孤独总比滥情好
    2020-12-30 10:43

    You can compare two NSDate objects using the isEqualToDate method, will return a bool (yes or no) telling you if the dates are equal. See Apple Documentation.

    As for the releasing the objects - the rule in objective-c is that you only release objects that you alloc memory for during the course of your method. The only object you're specifically allocating memory for in your code is comps so it's the only one you should release - and you've done so. Releasing memory for objects you never allocated is probably what is causing your app to crash. When the methods which actually allocated those objects attempts to release them or another reference to them tries to access them, they'll trigger an EXC_BAD_ACCESS error as you've already released them!

    So don't just comment out those release lines, delete them from your script - there's no need for them!

提交回复
热议问题