NSHipster Obscure Topics in Cocoa and Objective C

#pragma

1.Organizing Your Code

Use #pragma mark in your @implementation to divide code into logical sections. Not only do these sections make it easier to read through the code itself, but it also adds visual cues to the Xcode source navigator.使用 #pragma 标记在你的 @implementation里面把 代码分成逻辑部分。做这些标记不仅是代码本身变得易读,它还向 Xcode 源导航添加视觉线索。

#pragma mark declarations starting with a dash (-) are preceded with a horizontal divider.在#pragma和声明开始的前面有一个(-)水平分隔物

2.Inhibiting Warnings

Especially 3rd-party code. There are few things as irksome as that one vendor library that takes forever to compile, and finishes with 200+ warnings. Even shipping code with a single warning is in poor form.特别是第三方的代码,编译得得时候有200+多条警告是非常令人厌烦的。

Try setting the -Weverything flag and checking the "Treat Warnings as Errors" box your build settings. This turns on Hard Mode in Xcode.

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-variable"
    OSStatus status = SecItemExport(...);
    NSCAssert(status == errSecSuccess, @"%d", status);
#pragma clang diagnostic pop

You can read more about the LLVM's use of #pragma in the Clang Compiler User's Manual.