ios - 一个NSString的指针怎么判断是不是为null?
PHPz
PHPz 2017-04-18 09:45:40
0
1
590

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

PHPz
PHPz

学习是最好的投资!

reply all(1)
大家讲道理

Okay, I woke up after a good sleep and found that someone with the same question had already replied to me on Baozhan, so I’ll post it here... What I asked on Baozhan was why he used the address to communicate with NULL comparison, and then it was modified by someone. Why do we need to use a constant address to compare with NULL? Because that UIKey.....is indeed a constant
Okay, here is the reply that I think solved my problem "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.”

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template