如何创建一个常量 NSDate
我正在尝试定义 DateTime.MaxValue (C#) 的等效项,但在 Objective C 中。
我不想每次使用它时都继续创建 NSDates,所以我希望将其作为 const。
问题,编译器返回“Initializer element is not Constant”
下面是代码
static NSDate* DateTimeMinValue = [NSDateFormatter dateFromString:@"00:00:00.0000000, January 01, 1984"];
我还尝试了
NSDate* const DateTimeMinValue = [NSDateFormatter dateFromString:@"00:00:00.0000000, 1984 年 1 月 1 日"];
另外,static 和 const 之间有什么区别?
I am trying to define the equivalent of DateTime.MaxValue (C#) but in Objective C.
I don't want to keep creating NSDates every time I use it so I wish I had it as const.
The problem, the compiler returns "Initializer element is not constant"
Here is the code
static NSDate* DateTimeMinValue = [NSDateFormatter dateFromString:@"00:00:00.0000000, January 01, 1984"];
I also tried
NSDate* const DateTimeMinValue = [NSDateFormatter dateFromString:@"00:00:00.0000000, January 01, 1984"];
Also, what would the difference between the static and const be?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
虽然这不是您问题的确切答案,但它仍然可能对您有所帮助。
您是否读过或听说过
他们回来的
当您必须将日期与遥远的日期进行比较时,它们会非常方便。
While this is not the exact answer to your question it still might help you.
Did you ever read or hear about
they return
They come in quite handy when you have to compare dates to well a distant Date.
static 和 const 之间的区别是什么?
静态变量在应用程序运行会话的生命周期中存在,并且可以从类内部或其他类通过访问器来访问和更改。 const 变量不能被修改。
what would the difference between the static and const be?
Static variables exist for the life of the app's run session, and can be accessed and altered from within the class, or by other classes by way of accessors. Const variables cannot be modified.