Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Codable Option to make Codable Structs with forced up-wrapped properties #101

Merged
merged 2 commits into from
Nov 24, 2018

Conversation

mumer92
Copy link
Contributor

@mumer92 mumer92 commented Dec 26, 2017

This PR adds a new Language file that removes constructor and adds option to make explicitly unwrapped properties.

Using OpenWeather API:

{
  "coord": {
    "lon": 74.33,
    "lat": 31.52
  },
  "weather": [
    {
      "id": 711,
      "main": "Smoke",
      "description": "smoke",
      "icon": "50d"
    },
    {
      "id": 741,
      "main": "Fog",
      "description": "fog",
      "icon": "50d"
    }
  ],
  "base": "stations",
  "main": {
    "temp": 287.6,
    "pressure": 1020,
    "humidity": 67,
    "temp_min": 287.15,
    "temp_max": 288.15
  },
  "wind": {
    "speed": 1.96,
    "deg": 313.002
  },
  "clouds": {
    "all": 40
  },
  "dt": 1514264400,
  "sys": {
    "type": 1,
    "id": 7133,
    "message": 0.0039,
    "country": "PK",
    "sunrise": 1514253615,
    "sunset": 1514289990
  },
  "id": 1172451,
  "name": "Lahore",
  "cod": 200
}

Generated to:

import Foundation

struct RootClass : Codable {
	let base : String
	let clouds : Cloud
	let cod : Int
	let coord : Coord
	let dt : Int
	let id : Int
	let main : Main
	let name : String
	let sys : Sy
	let weather : [Weather]
	let wind : Wind


	enum CodingKeys: String, CodingKey {
		case base = "base"
		case clouds
		case cod = "cod"
		case coord
		case dt = "dt"
		case id = "id"
		case main
		case name = "name"
		case sys
		case weather = "weather"
		case wind
	}
}


import Foundation

struct Wind : Codable {

	let deg : Float
	let speed : Float


	enum CodingKeys: String, CodingKey {
		case deg = "deg"
		case speed = "speed"
	}


}

import Foundation

struct Weather : Codable {

	let descriptionField : String
	let icon : String
	let id : Int
	let main : String


	enum CodingKeys: String, CodingKey {
		case descriptionField = "description"
		case icon = "icon"
		case id = "id"
		case main = "main"
	}
}

import Foundation

struct Sy : Codable {
	let country : String
	let id : Int
	let message : Float
	let sunrise : Int
	let sunset : Int
	let type : Int


	enum CodingKeys: String, CodingKey {
		case country = "country"
		case id = "id"
		case message = "message"
		case sunrise = "sunrise"
		case sunset = "sunset"
		case type = "type"
	}
}


import Foundation

struct Main : Codable {

	let humidity : Int
	let pressure : Int
	let temp : Float
	let tempMax : Float
	let tempMin : Float


	enum CodingKeys: String, CodingKey {
		case humidity = "humidity"
		case pressure = "pressure"
		case temp = "temp"
		case tempMax = "temp_max"
		case tempMin = "temp_min"
	}
}


import Foundation

struct Coord : Codable {

	let lat : Float
	let lon : Float


	enum CodingKeys: String, CodingKey {
		case lat = "lat"
		case lon = "lon"
	}
}

import Foundation

struct Cloud : Codable {

	let all : Int

	enum CodingKeys: String, CodingKey {
		case all = "all"
	}
}

@Ahmed-Ali Ahmed-Ali merged commit 2f8ba42 into Ahmed-Ali:master Nov 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants