Defaults icon indicating copy to clipboard operation
Defaults copied to clipboard

Cannot conform to protocol on Xcode 13.3 beta - macOS 12.3

Open Wouter01 opened this issue 3 years ago • 14 comments

Yesterday I updated Xcode to version 13.3, and now there are a number of errors about DefaultsSerializable. When creating a new project and adding the example code from here, I get the same error. image

Wouter01 avatar Jan 28 '22 19:01 Wouter01

This looks like a Swift regression: https://bugs.swift.org/projects/SR/issues/SR-15807

sindresorhus avatar Feb 03 '22 18:02 sindresorhus

Workaround:

struct MyBridge<Value: Codable>: DefaultsCodableBridge {}

extension User: Defaults.Serializable {
  static let bridge = MyBridge<User>()
}

ibash avatar Feb 10 '22 03:02 ibash

Any workaround for enums?

quantamrhino avatar Feb 21 '22 13:02 quantamrhino

@hank121314 It doesn't look like Swift will fix this in time for Xcode 13.3 final. Any idea how we could work around this in Defaults for now?

sindresorhus avatar Feb 26 '22 11:02 sindresorhus

This issue seems to occur when using the type which has multiple protocol conformance across module. The temporary workaround might be declared the protocol conformance in the same module. Here are my workaround steps:

  1. Create Defaults+WorkAround.swift in the module which is using Defaults.
  2. Copy the codes below into Defaults+WorkAround.swift
import Defaults
import Foundation

extension Defaults.Serializable where Self: Codable {
	public static var bridge: Defaults.TopLevelCodableBridge<Self> { Defaults.TopLevelCodableBridge() }
}

extension Defaults.Serializable where Self: Codable & NSSecureCoding {
	public static var bridge: Defaults.CodableNSSecureCodingBridge<Self> { Defaults.CodableNSSecureCodingBridge() }
}

extension Defaults.Serializable where Self: Codable & NSSecureCoding & Defaults.PreferNSSecureCoding {
	public static var bridge: Defaults.NSSecureCodingBridge<Self> { Defaults.NSSecureCodingBridge() }
}

extension Defaults.Serializable where Self: Codable & RawRepresentable {
	public static var bridge: Defaults.RawRepresentableCodableBridge<Self> { Defaults.RawRepresentableCodableBridge() }
}

extension Defaults.Serializable where Self: Codable & RawRepresentable & Defaults.PreferRawRepresentable {
	public static var bridge: Defaults.RawRepresentableBridge<Self> { Defaults.RawRepresentableBridge() }
}

extension Defaults.Serializable where Self: RawRepresentable {
	public static var bridge: Defaults.RawRepresentableBridge<Self> { Defaults.RawRepresentableBridge() }
}
extension Defaults.Serializable where Self: NSSecureCoding {
	public static var bridge: Defaults.NSSecureCodingBridge<Self> { Defaults.NSSecureCodingBridge() }
}

extension Defaults.CollectionSerializable where Element: Defaults.Serializable {
	public static var bridge: Defaults.CollectionBridge<Self> { Defaults.CollectionBridge() }
}

extension Defaults.SetAlgebraSerializable where Element: Defaults.Serializable & Hashable {
	public static var bridge: Defaults.SetAlgebraBridge<Self> { Defaults.SetAlgebraBridge() }
}

And to achieve this workaround we might also need to public some bridge initializers. Not sure whether this is an acceptable solution. 😢

hank121314 avatar Feb 27 '22 05:02 hank121314

Yeah, that's a good enough workaround.

sindresorhus avatar Feb 28 '22 14:02 sindresorhus

Have same issue on Release Xcode 13.3 version 😢

nab0y4enko avatar Mar 15 '22 13:03 nab0y4enko

Hi @nab0y4enko. I am working on this, sorry for the inconvenience 😞 .

hank121314 avatar Mar 15 '22 13:03 hank121314

Hi @nab0y4enko. I am working on this, sorry for the inconvenience 😞 .

Still buggy in 13.3 stable release...

It's always a mess after upgrading Xcode, especially with a newer Swift version... Thanks for the hard work anyway!

Hoping to see this issue to be fixed soon...

RoyRao2333 avatar Mar 15 '22 16:03 RoyRao2333

I recommend anyone looking here to also report this through Feedback Assistant. Just link to the Swift issue.

sindresorhus avatar Mar 15 '22 17:03 sindresorhus

https://github.com/sindresorhus/Defaults/releases/tag/v6.2.1

sindresorhus avatar Mar 15 '22 17:03 sindresorhus

Workaround + v6.2.1 worked.😄😄

owenzhao avatar Mar 16 '22 03:03 owenzhao

To whom it may concern that have custom Codable struct/class and looking for workaround (using the example of NSRect):

extension NSRect: Defaults.Serializable {
	// TODO: A temporary workaround for Xcode 13.3 compiler issue. Should remove after https://bugs.swift.org/browse/SR-15807 is fixed.
	public static var bridge: Defaults.TopLevelCodableBridge<NSRect> { Defaults.TopLevelCodableBridge() }
}

Maschina avatar Mar 16 '22 10:03 Maschina

@hank121314 Congrats on getting your pull request merged on the Swift repo: https://github.com/apple/swift/pull/42293 And thank you so much for fixing this issue in Swift 🎉

sindresorhus avatar May 06 '22 09:05 sindresorhus

Closing as Xcode 14 is out now.

sindresorhus avatar Sep 22 '22 16:09 sindresorhus