How to suppress a specific warning in Swift

倖福魔咒の 提交于 2019-12-04 06:23:41
Martin R

At present (Xcode 7.1), there seems to be no way of suppressing a specific warning in Swift (see e.g. How to silence a warning in swift).

In your special case, you can fool the compiler by computing the number of bytes in a word:

func f() -> Int {
    switch (__WORDSIZE / CHAR_BIT) { // Or: switch (sizeof(Int.self))
    case 4: return 1
    case 8: return 2
    default: return 0
    }
}

This compiles without warnings on both 32-bit and 64-bit architectures.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!