How to determine if compiling for 64-bit iOS in Xcode

前端 未结 2 500
栀梦
栀梦 2021-02-13 00:56

Consider the following function

CGSize CGSizeIntegral(CGSize size)
{
    return CGSizeMake(ceilf(size.width), ceilf(size.height));
}

CGSi

2条回答
  •  感动是毒
    2021-02-13 01:17

    For Swift, and neglecting the OP's specific question involving CGFloats, etc., the following may be more swiftish:

      #if (arch(i386) || arch(arm))
         ....  // For 32-bit systems
      #else
         ....  // For 64-bit systems
      #endif
    
    
      #if (arch(x86_64) || arch(arm64))
         ....  // For 64-bit systems
      #endif
    

    On the other hand, the compile-time constants discussed in the above answer are also available in Swift, if they are preferred.

    This is mostly copied from here: https://stackoverflow.com/a/24869607/253938

    And the Apple docs about these Swift compile-time constants is here: https://developer.apple.com/library/content/documentation/Swift/Conceptual/BuildingCocoaApps/InteractingWithCAPIs.html (at the very bottom of the page).

提交回复
热议问题