Fixtures.swift 1013 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
//
//  Fixtures.swift
//  Api
//
//  Created by Mauro Bender on 13/8/16.
//  Copyright © 2016 CocoaPods. All rights reserved.
//

import Api

struct Item {
	let id: Int
	let name: String
}

extension Item: JSONSerializable {
	init(fromJSON json: [String : AnyObject]) {
		self.id   = json[ "id" ] as! Int
		self.name = json[ "name" ] as! String
	}
	
	func toJSON() -> [String : AnyObject] {
23
24
25
26
27
28
		var json = [ String: AnyObject ]()
		
		if id > 0 { json[ "id" ] = id }
		json[ "name" ] = name
		
		return json
29
	}
30
31
32
33
34
35
}

extension Item: Equatable {}

func ==(lhs: Item, rhs: Item) -> Bool {
	return lhs.id == rhs.id && lhs.name == rhs.name
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
}

struct Component {
	let id: Int
	let name: String
}

extension Component: JSONSerializable {
	init(fromJSON json: [String : AnyObject]) {
		self.id   = json[ "id" ] as! Int
		self.name = json[ "name" ] as! String
	}
	
	func toJSON() -> [String : AnyObject] {
		var json = [ String: AnyObject ]()
		
		if id > 0 { json[ "id" ] = id }
		json[ "name" ] = name
		
		return json
	}
57
}