jeudi 25 juillet 2019

Will swift mirror keep the property order?

We can iterate with (name, value) tuple, but are they coming the same order as we defined it? Let's go with the

struct Book {
    let title: String
    let author: String?
    let published: Date
    let numberOfPages: Int
    let chapterCount: Int?
    let genres: [String]
}

And the result is:

// title: String = 'Harry Potter'
// author: Optional<String> = 'Optional("J.K. Rowling")'
// published: Date = '2016-10-02 19:17:43 +0000'
// numberOfPages: Int = '450'
// chapterCount: Optional<Int> = 'Optional(19)'
// genres: Array<String> = '["Fantasy", "Best books ever"]'

Check the order: it's very same. Can we be sure, that it's the same? (Code snippets are from https://makeitnew.io/reflection-in-swift-68a06ba0cf0e)





Aucun commentaire:

Enregistrer un commentaire