Checking the implementation of SwiftUI on iOS 15.5
struct SwiftUI._Velocity<A> where A: Equatable{
var valuePerSecond: A
}
It already has a "Equtable" constraint on _Velocity's generic type. So the conformance seems reasonable for me.
I guess with iOS 16/17 SDK, Apple has moved extension CGSize: Swift.Equatable
or CGSize
def to somewhere else. And that's the problem here.
On iOS 15.5 SDK, CGSize
is defined on CoreGraphics
. So if the Equatable
conformance is also defined on CoreGraphics
, the conformance is not a RetroactiveConformance.
// CoreGraphics - CGGeometry.h
/* Sizes. */
struct CGSize {
CGFloat width;
CGFloat height;
};
typedef struct CG_BOXABLE CGSize CGSize;
However on iOS 17.0 SDK, CGSize
is defined on CoreFoundation
instead. Then the conformance would be a RetroactiveConformance.
// CoreGraphics - CGGeometry.h
#ifndef CF_DEFINES_CG_TYPES
/* Sizes. */
struct CGSize {
CGFloat width;
CGFloat height;
};
typedef struct CG_BOXABLE CGSize CGSize;
...
#endif /* CF_DEFINES_CG_TYPES */
// CoreFoundation - CFCGTypes.h
...
#define CF_DEFINES_CG_TYPES
struct CGSize {
CGFloat width;
CGFloat height;
};
typedef struct CF_BOXABLE CGSize CGSize;
I was wondering how Apple keeps such compatibility for other public binary. You need to find a public symbol in Apple's system framework which use CGSize as generic type conforming to Equatable
type just like this one. Then we can continue the investigation. cc @DevAndArtist
If you can find another public one, two results:
- It works fine. Then we can check the magic Apple is using. And try to apply it to our case.
- It does not work and crash too. Since this a public symbol, then you can file a FB and ask for a fix for it. Hopefully we'll get a new Xcode/iOS SDK later to fix the
compatibility issue.
Here are some of my irresponsible personal guesses.
I found that many types of CG on Linux are defined in the Foundation module of swift-corelibs-foundation defined using Swift. But on previous Darwin platform, they were defined on CoreGraphics
module.
So I often need to use the following code to use CG
type on my cross-platform package.
With the launch of the new swift-foundation and Apple want to make it universal in all platforms Swift support, I guess Apple then decided to move these CG types to CoreFoundation which exist on Linux as an implementation detail.