Uploaded image for project: 'Swift'
  1. Swift
  2. SR-8001

Codable does not synthesize init(from:) and encode(to:) for computed properties with getters and setters

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: Medium
    • Resolution: Unresolved
    • Component/s: Compiler
    • Labels:
    • Environment:

      Version 10.0 beta

      macOS App

      Description

      struct City : Codable {    
          private enum CodingKeys: String, CodingKey {        
              case coordinates = "latt_long"
          }
      
      
          public var coordinates: String? {
              get {
                  return "(lat, long)"
              }
      
              set {
                  if let coordString = newValue {
                      let coords = coordString.replacingOccurrences(of: " ", with: "")
                      let coordsArray = coords.split(separator: ",")
                      self.lat = Float(Int("(String(describing: coordsArray.first))") ?? 0)
                      self.long = Float(Int("(String(describing: coordsArray.last))") ?? 0)
                  }
              }
          }
      
          /* Coordinates set these */
          private(set) var lat: Float?
          private(set) var long: Float?
      }
      
      **Coding.swift:24:14: CodingKey case 'coordinates' does not match any stored properties
      

        Attachments

          Activity

            People

            • Assignee:
              itaiferber Itai Ferber
              Reporter:
              chih98 Marko Crnkovic
            • Votes:
              1 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated: