Strict Type Checking in Objective-C via Macros

前端 未结 3 1917
我在风中等你
我在风中等你 2021-01-15 16:08

Occasionally, during development/debugging, I want to ensure that an object is of a certain type:

PageTopBottom *newPage = [notification object];
assert([new         


        
3条回答
  •  别那么骄傲
    2021-01-15 16:34

    The preprocessor only processes text; it has no knowledge of type, which is why it's sometimes considered 'dangerous'. The only way I could see doing it is wrapping the variable declarations in a macro, which I would strongly advise against, and probably wouldn't actually cut down on the code or complexity.

    Also, shouldn't you check the type before casting?

提交回复
热议问题