最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

ios - Removing all the Mock JSON fixtures to convert it into methods for the similar use - Stack Overflow

programmeradmin4浏览0评论

In my project, we have 1000+ fixtures (mock JSON) files. I am required to find a way to remove all these JSON files, and use .mock() methods instead. Here is an example:

struct Person {
var name: String?
var age: Int
}

The hardcoded JSON (fixture) is as follows:

{
"__typename": "Person",
"name": "Sarthak",
"age": 27
}

I want a mock method such as

static func mockPerson() -> Person? {
.init(name: "Sarthak", age: 27)
}

Now, I can manually change this, but is there a way to automate something like this for 1000+ fixtures that I have/? Maybe __typename can be mapped.

发布评论

评论列表(0)

  1. 暂无评论