Skip to content

Commit f89cae6

Browse files
author
Bradley S. Maskell
authored
Library Evolution Support (Flight-School#37)
* enabled library evolution support * annotated public structs with @Frozen to prevent crashes if referenced in a file initialized by a storybaord. https://bugs.swift.org/browse/SR-11969 * Added a swift version check for older versions of Swift that don't support `@frozen` * `@frozen` is only available in swift 5.1
1 parent c99eb36 commit f89cae6

File tree

4 files changed

+38
-3
lines changed

4 files changed

+38
-3
lines changed

AnyCodable.xcodeproj/project.pbxproj

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@
112112
name = Products;
113113
sourceTree = BUILT_PRODUCTS_DIR;
114114
};
115-
OBJ_5 /* */ = {
115+
OBJ_5 = {
116116
isa = PBXGroup;
117117
children = (
118118
OBJ_6 /* Package.swift */,
@@ -125,7 +125,6 @@
125125
OBJ_23 /* README.md */,
126126
OBJ_24 /* AnyCodable.xcconfig */,
127127
);
128-
name = "";
129128
sourceTree = "<group>";
130129
};
131130
OBJ_7 /* Sources */ = {
@@ -214,7 +213,7 @@
214213
English,
215214
en,
216215
);
217-
mainGroup = OBJ_5 /* */;
216+
mainGroup = OBJ_5;
218217
productRefGroup = OBJ_17 /* Products */;
219218
projectDirPath = "";
220219
projectRoot = "";
@@ -275,6 +274,7 @@
275274
OBJ_27 /* Debug */ = {
276275
isa = XCBuildConfiguration;
277276
buildSettings = {
277+
BUILD_LIBRARY_FOR_DISTRIBUTION = YES;
278278
DYLIB_COMPATIBILITY_VERSION = 1;
279279
DYLIB_CURRENT_VERSION = 1;
280280
ENABLE_TESTABILITY = YES;
@@ -305,6 +305,7 @@
305305
OBJ_28 /* Release */ = {
306306
isa = XCBuildConfiguration;
307307
buildSettings = {
308+
BUILD_LIBRARY_FOR_DISTRIBUTION = YES;
308309
DYLIB_COMPATIBILITY_VERSION = 1;
309310
DYLIB_CURRENT_VERSION = 1;
310311
ENABLE_TESTABILITY = YES;
@@ -362,6 +363,7 @@
362363
OBJ_36 /* Debug */ = {
363364
isa = XCBuildConfiguration;
364365
buildSettings = {
366+
BUILD_LIBRARY_FOR_DISTRIBUTION = YES;
365367
LD = /usr/bin/true;
366368
OTHER_SWIFT_FLAGS = "-swift-version 5 -I $(TOOLCHAIN_DIR)/usr/lib/swift/pm/4_2 -target x86_64-apple-macosx10.10 -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk";
367369
SWIFT_VERSION = 5.0;
@@ -371,6 +373,7 @@
371373
OBJ_37 /* Release */ = {
372374
isa = XCBuildConfiguration;
373375
buildSettings = {
376+
BUILD_LIBRARY_FOR_DISTRIBUTION = YES;
374377
LD = /usr/bin/true;
375378
OTHER_SWIFT_FLAGS = "-swift-version 5 -I $(TOOLCHAIN_DIR)/usr/lib/swift/pm/4_2 -target x86_64-apple-macosx10.10 -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk";
376379
SWIFT_VERSION = 5.0;
@@ -404,12 +407,14 @@
404407
OBJ_42 /* Debug */ = {
405408
isa = XCBuildConfiguration;
406409
buildSettings = {
410+
BUILD_LIBRARY_FOR_DISTRIBUTION = YES;
407411
};
408412
name = Debug;
409413
};
410414
OBJ_43 /* Release */ = {
411415
isa = XCBuildConfiguration;
412416
buildSettings = {
417+
BUILD_LIBRARY_FOR_DISTRIBUTION = YES;
413418
};
414419
name = Release;
415420
};

Sources/AnyCodable/AnyCodable.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,23 @@
1111
- SeeAlso: `AnyEncodable`
1212
- SeeAlso: `AnyDecodable`
1313
*/
14+
#if swift(>=5.1)
15+
@frozen public struct AnyCodable: Codable {
16+
public let value: Any
17+
18+
public init<T>(_ value: T?) {
19+
self.value = value ?? ()
20+
}
21+
}
22+
#else
1423
public struct AnyCodable: Codable {
1524
public let value: Any
1625

1726
public init<T>(_ value: T?) {
1827
self.value = value ?? ()
1928
}
2029
}
30+
#endif
2131

2232
extension AnyCodable: _AnyEncodable, _AnyDecodable {}
2333

Sources/AnyCodable/AnyDecodable.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,23 @@ import Foundation
3030
let decoder = JSONDecoder()
3131
let dictionary = try! decoder.decode([String: AnyDecodable].self, from: json)
3232
*/
33+
#if swift(>=5.1)
34+
@frozen public struct AnyDecodable: Decodable {
35+
public let value: Any
36+
37+
public init<T>(_ value: T?) {
38+
self.value = value ?? ()
39+
}
40+
}
41+
#else
3342
public struct AnyDecodable: Decodable {
3443
public let value: Any
3544

3645
public init<T>(_ value: T?) {
3746
self.value = value ?? ()
3847
}
3948
}
49+
#endif
4050

4151
#if swift(>=4.2)
4252
@usableFromInline

Sources/AnyCodable/AnyEncodable.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,23 @@ import Foundation
2828
let encoder = JSONEncoder()
2929
let json = try! encoder.encode(dictionary)
3030
*/
31+
#if swift(>=5.1)
32+
@frozen public struct AnyEncodable: Encodable {
33+
public let value: Any
34+
35+
public init<T>(_ value: T?) {
36+
self.value = value ?? ()
37+
}
38+
}
39+
#else
3140
public struct AnyEncodable: Encodable {
3241
public let value: Any
3342

3443
public init<T>(_ value: T?) {
3544
self.value = value ?? ()
3645
}
3746
}
47+
#endif
3848

3949
#if swift(>=4.2)
4050
@usableFromInline

0 commit comments

Comments
 (0)