Files
swift-mirror/stdlib/public/SDK/Foundation/CMakeLists.txt
Joe Groff 86fbeee285 SE-0139: Bridge Cocoa framework structs to NSValue.
For every struct type for which the frameworks provides an NSValue category for boxing and unboxing values of that type, provide an _ObjectiveCBridgeable conformance in the Swift overlay that bridges that struct to NSValue, allowing the structs to be used naturally with id-as-Any APIs and Cocoa container classes. This is mostly a matter of gyb-ing out boilerplate using `NSValue.init(bytes:objCType:)` to construct the instance, `NSValue.objCType` to check its type when casting, and `NSValue.getValue(_:)` to extract the unboxed value, though there are a number of special snowflake cases that need special accommodation:

- To maintain proper layering, CoreGraphics structs need to be bridged in the Foundation overlay.
- AVFoundation provides the NSValue boxing categories for structs owned by CoreMedia, but it does so using its own internal subclasses of NSValue, and these subclasses do not interop properly with the standard `NSValue` subclasses instantiated by Foundation. To do the right thing, we therefore have to let AVFoundation provide the bridging implementation for the CoreMedia types, and we have to use its category methods to do so.
- SceneKit provides NSValue categories to box and unbox SCNVector3, SCNVector4, and SCNMatrix4; however, the methods it provides do so in an unusual way. SCNVector3 and SCNVector4 are packaged into `CGRect`s and then the CGRect is boxed using `valueWithCGRect:`. SCNMatrix4 is copied into a CATransform3D, which is then boxed using `valueWithCATransform3D:` from CoreAnimation. To be consistent with what SceneKit does, use its category methods for these types as well, and when casting, check the type against the type encoding SceneKit uses rather than the type encoding of the expected type.
2016-09-21 19:26:10 -07:00

44 lines
988 B
CMake

add_swift_library(swiftFoundation ${SWIFT_SDK_OVERLAY_LIBRARY_BUILD_TYPES} IS_SDK_OVERLAY
Foundation.swift
Boxing.swift
NSError.swift
NSStringAPI.swift
NSValue.swift.gyb
ExtraStringAPIs.swift
ReferenceConvertible.swift
AffineTransform.swift
Calendar.swift
TimeZone.swift
Locale.swift
CharacterSet.swift
Date.swift
DateComponents.swift
DateInterval.swift
Data.swift
DataThunks.m
Decimal.swift
FileManager.swift
FileManagerThunks.m
IndexPath.swift
IndexSet.swift
IndexSetThunks.m
Measurement.swift
Notification.swift
NSStringEncodings.swift
PersonNameComponents.swift
TypePreservingNSNumber.mm
URL.swift
URLComponents.swift
URLRequest.swift
UUID.swift
Hashing.swift
Hashing.m
Thunks.mm
SWIFT_COMPILE_FLAGS "${SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS}"
LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}"
SWIFT_MODULE_DEPENDS ObjectiveC CoreGraphics Dispatch os
SWIFT_MODULE_DEPENDS_OSX XPC
FRAMEWORK_DEPENDS Foundation)