如何在 xcode 中按天循环和数组索引
我知道这个问题听起来有点好笑。
我正在尝试在 iPhone 项目中向下移动数组列表。
我有一个包含 100 个项目的数组: [0][1]...[99]
我想今天选择索引[0],明天选择索引[1]...100 天后索引[99]。然后在第 101 天,回到索引 [0]。
也许我需要转换 NSDate 并以日期格式获取今天的日期?那么今天是 285/365,然后对我的数组执行一些操作以根据今天的日期/日期循环它?
I know the question sounds a little funny.
I am trying to move down the list of array in my iPhone project.
I have an array of 100 items:
[0][1]...[99]
I would like to select index[0] today, index[1] tomorrow... index[99] 100 days from now. And then on day 101, back to index [0].
Maybe I need to convert NSDate and get todays date in a day format? So today would be 285/365 and then do something with my array to loop it according to today's date/day?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从朋友那里得到了答案。答案就是模运算!
现在我只需要研究如何将 NSDate 转换为一年中的天数。
10 月 13 日 = 286
Got the answer from a friend. Modulo Operation is the answer!
Now I just need to research on how to convert NSDate into days of the year.
October 13th = 286
这个怎么样:
How about this: