ios - 一个NSString的指针怎么判断是不是为null?
PHPz
PHPz 2017-04-18 09:45:40
[iOS讨论组]

#define _UIKeyboardFrameEndUserInfoKey (&UIKeyboardFrameEndUserInfoKey != NULL ? UIKeyboardFrameEndUserInfoKey : @"UIKeyboardBoundsUserInfoKey")这段代码我知道是什么意思,但是不明白为什么判断是不是NULL的时候要对变量先取址?我自己写代码测试时会有警告,说拿地址跟非NULL比较永远都是true

PHPz
PHPz

学习是最好的投资!

全部回复(1)
大家讲道理

好吧,睡了一觉起来,发现同样的问题在爆栈上已经有大神回复我了,我就贴在这里好了……在爆栈上我问的是为啥他要用地址去和NULL比较,然后被人修改为了为何要用常量的地址去和NULL比较?因为那个UIKey.....确实是常量
好下面是我认为解决我问题的回复“Comparing the address of a constant (or function) to null is generally used to determine if the constant is defined.

You're getting the warning because the SDK that you're building against (minimum target version) has the constant defined, so it will always evaluate to true (the address won't be null). However, when run on a version of iOS that doesn't have the constant defined, it will not be true (the address will be null).

If you lowered the target version to a version below where the constant were defined, it would weakly link to that SDK, and you would no longer receive the warning.”

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号