3

I'm in the process of updating some code to use Xcode 13.3 and came across some new warnings that I'm unsure how to remove. Here's the gist of the code:

struct Link: Codable {
    let href: URL
}

struct FooLinks: Codable {
    let `self`: Link // <--- this is the culprit
}

struct Foo: Codable {
    let links: FooLinks
}

The warnings don't show up in the editor, only in the build log, and are as follows:

<unknown>:0: warning: 'self' refers to the method 'Foo.FooLinks.CodingKeys.self', which may be unexpected
<unknown>:0: note: use 'Foo.FooLinks.CodingKeys.self' to silence this warning
<unknown>:0: warning: 'self' refers to the method 'Foo.FooLinks.self', which may be unexpected
<unknown>:0: note: use 'Foo.FooLinks.self' to silence this warning
<unknown>:0: warning: 'self' refers to the method 'Foo.FooLinks.self', which may be unexpected
<unknown>:0: note: use 'Foo.FooLinks.self' to silence this warning

None of the suggested fixes make any sense to me. Is there a way to get rid of the warnings without renaming the offending self property?

Gereon
  • 17,258
  • 4
  • 42
  • 73
  • 1
    Rename it. Calling a member self is outrageously bad. – gnasher729 Mar 22 '22 at 13:23
  • @gnasher729 that's unfortunately part of the JSON API I'm given, and while this use of `self` in Swift or Obj-C is certainly not ideal, "self" links in a REST API are indeed pretty useful. – Gereon Mar 22 '22 at 14:34
  • The properties in the Swift type don't have to match one-to-one the names in the JSON (though keeping them consistent is generally helpful). You have to write a little more Codable code, but you _can_ call it something else. – Sixten Otto Mar 22 '22 at 19:04
  • Thanks, I know that. The point here is that this warning looks like a regression to me, since the code compiled without problems with previous releases. – Gereon Mar 22 '22 at 21:41

1 Answers1

0

This issue has been resolved in Xcode 14.0 beta

Gereon
  • 17,258
  • 4
  • 42
  • 73