Hi @mythz ,
I noticed that you added support for Codable on the last version of the swift client.
I was just giving it a try on one of my projects, but while it generated the code correctly it doesn’t compile because it gives a lot of error.
I have cleared the cache to get the latest ServiceStack server, updated the X tool, and referenced the last swift client from Github.
All error look the same, here an excerpt of the errors, and a gist with the dto file
type 'GetAppConfig' does not conform to protocol 'IReturn'
Type 'SearchListing' does not conform to protocol 'IReturn'
Type 'AppConfigResponse' does not conform to protocol 'Decodable'
I’m assuming that’s because you’re still using the older ServiceStack.Swift release, try the latest 5.0.0 major version which has been rewritten to use the new Codable support:
Ok tested a little and works greats, this is good update.
I was just wondering yesterday about codable support, now I can add mock json data and load them in memory for SwiftUI previews
Sweet, Happy to hear it, yeah was good to remove all the machinery required to make JSON DTOs work previously and use Swift’s Codable support now that its standardized and has support built-into the compiler which I’d expect to be both ubiquitous and stable going forward.
Most of the time the Swift compiler will be able to generate the default implementations for most DTOs but wont for inherited classes or for Request DTOs which self references themselves, e.g. when returning themselves with IReturn<RequestDto> in which case we’ll generate the explicit Codable implementations. Should you ever want to have explicit implementations generated for a DTO you can opt-in with the new [Synthesize] attribute.
Yeah thought I did publish to CocoaPods but tried to again and looked like my login session had expired, it should be up there now.
On a side note: I had to abandon Carthage for managing ServiceStack.Swift’s PromiseKit dependency which didn’t properly support Xcode 12, only way I could get the project to build was to convert ServiceStack.Swift into a pure Swift Package Manager project. Anyway if you have issues using Carthage with Xcode 12 I recommend abandoning it and starting from a new Swift Package Manager project.
Good thanks.
Yeah i’m still using cocoapods only, in a few project for two reasons:
A few deps still don’t have swiftpm
Because i noticed that every time in a project i add or convert to SwiftPM, Xcode start behaving badly with intellisense it stop working multiple times in a day and a general slow down of the ide
Just noticed a little issue, when the swift dtos get generated, I get wrong name casing for the property named description.
For example this c# dto
public class FullListing
{
public int Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public string CategoryName { get; set; }
public string FullAddress {get; set;}
public string PictureUrl { get; set; }
public string Phone { get; set; }
public string MobilePhone { get; set; }
public string Email { get; set; }
}
get generated on swift side as
public class FullListing : Codable
{
public var id:Int?
public var name:String?
public var Description:String?
public var categoryName:String?
public var fullAddress:String?
public var pictureUrl:String?
public var phone:String?
public var mobilePhone:String?
public var email:String?
required public init(){}
}
Because of this description field is not deserialized but all other fields are fine.
It needs to use a different property name because it can’t override NSObject’s description computed property.
There’s not an easy solution other than synthesizing the whole DTO and overriding the coding keys. Unless we can customize JSONDecoder to ignore casing, i’ll see if there is.