Skip to content

Commit

Permalink
Improve codes
Browse files Browse the repository at this point in the history
  • Loading branch information
to4iki committed Apr 26, 2018
1 parent 88075b3 commit f058c25
Show file tree
Hide file tree
Showing 18 changed files with 89 additions and 164 deletions.
62 changes: 35 additions & 27 deletions OctavKit.xcodeproj/project.pbxproj
Expand Up @@ -50,8 +50,8 @@
dstPath = "";
dstSubfolderSpec = 10;
files = (
4407ED391F260DF200A8137D /* Result.framework in Copy Frameworks */,
4407ED3A1F260DF200A8137D /* Himotoki.framework in Copy Frameworks */,
4407ED391F260DF200A8137D /* Result.framework in Copy Frameworks */,
);
name = "Copy Frameworks";
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -98,15 +98,23 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
1E8C89981F21DD4B00D2BB10 /* Result.framework in Frameworks */,
1E8C89991F21DD4B00D2BB10 /* Himotoki.framework in Frameworks */,
1E7EC5F71F21D99F00E43AD2 /* OctavKit.framework in Frameworks */,
1E8C89981F21DD4B00D2BB10 /* Result.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
1E1F90CC2092166C0095103A /* Core */ = {
isa = PBXGroup;
children = (
1E8C89751F21DC7D00D2BB10 /* ParameterHolder.swift */,
);
path = Core;
sourceTree = "<group>";
};
1E7EC5E31F21D99F00E43AD2 = {
isa = PBXGroup;
children = (
Expand All @@ -129,10 +137,11 @@
1E7EC5EF1F21D99F00E43AD2 /* OctavKit */ = {
isa = PBXGroup;
children = (
1E8C89721F21DC7D00D2BB10 /* api */,
1E8C89761F21DC7D00D2BB10 /* extension */,
1E8C89791F21DC7D00D2BB10 /* model */,
1E8C89841F21DC7D00D2BB10 /* request */,
1E8C89721F21DC7D00D2BB10 /* Api */,
1E1F90CC2092166C0095103A /* Core */,
1E8C89761F21DC7D00D2BB10 /* Extension */,
1E8C89841F21DC7D00D2BB10 /* Request */,
1E8C89791F21DC7D00D2BB10 /* Response */,
1E7EC5F11F21D99F00E43AD2 /* Info.plist */,
1E7EC5F01F21D99F00E43AD2 /* OctavKit.h */,
1E8C89831F21DC7D00D2BB10 /* OctavKit.swift */,
Expand All @@ -152,32 +161,31 @@
1E8C896D1F21DBBA00D2BB10 /* Frameworks */ = {
isa = PBXGroup;
children = (
1E8C896E1F21DBBA00D2BB10 /* Result.framework */,
1E8C896F1F21DBBA00D2BB10 /* Himotoki.framework */,
1E8C896E1F21DBBA00D2BB10 /* Result.framework */,
);
name = Frameworks;
sourceTree = "<group>";
};
1E8C89721F21DC7D00D2BB10 /* api */ = {
1E8C89721F21DC7D00D2BB10 /* Api */ = {
isa = PBXGroup;
children = (
1E8C89731F21DC7D00D2BB10 /* OctavAPI.swift */,
1E8C89741F21DC7D00D2BB10 /* OctavAPIError.swift */,
1E8C89751F21DC7D00D2BB10 /* ParameterHolder.swift */,
);
path = api;
path = Api;
sourceTree = "<group>";
};
1E8C89761F21DC7D00D2BB10 /* extension */ = {
1E8C89761F21DC7D00D2BB10 /* Extension */ = {
isa = PBXGroup;
children = (
1E8C89781F21DC7D00D2BB10 /* Date+ISO8601.swift */,
1E8C89771F21DC7D00D2BB10 /* Date+components.swift */,
1E8C89781F21DC7D00D2BB10 /* Date+ISO8601.swift */,
);
path = extension;
path = Extension;
sourceTree = "<group>";
};
1E8C89791F21DC7D00D2BB10 /* model */ = {
1E8C89791F21DC7D00D2BB10 /* Response */ = {
isa = PBXGroup;
children = (
1E8C897A1F21DC7D00D2BB10 /* Conference.swift */,
Expand All @@ -189,16 +197,16 @@
1E8C89811F21DC7D00D2BB10 /* Track.swift */,
1E8C89821F21DC7D00D2BB10 /* Venue.swift */,
);
path = model;
path = Response;
sourceTree = "<group>";
};
1E8C89841F21DC7D00D2BB10 /* request */ = {
1E8C89841F21DC7D00D2BB10 /* Request */ = {
isa = PBXGroup;
children = (
1E8C89851F21DC7D00D2BB10 /* HTTPMethod.swift */,
1E8C89861F21DC7D00D2BB10 /* Request.swift */,
);
path = request;
path = Request;
sourceTree = "<group>";
};
/* End PBXGroup section */
Expand Down Expand Up @@ -314,22 +322,22 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
1E8C89921F21DC7D00D2BB10 /* Sponsor.swift in Sources */,
1E8C898C1F21DC7D00D2BB10 /* Conference.swift in Sources */,
1E8C898A1F21DC7D00D2BB10 /* Date+components.swift in Sources */,
1E8C898B1F21DC7D00D2BB10 /* Date+ISO8601.swift in Sources */,
1E8C89961F21DC7D00D2BB10 /* HTTPMethod.swift in Sources */,
1E8C89871F21DC7D00D2BB10 /* OctavAPI.swift in Sources */,
1E8C89941F21DC7D00D2BB10 /* Venue.swift in Sources */,
1E8C89951F21DC7D00D2BB10 /* OctavKit.swift in Sources */,
1E8C898F1F21DC7D00D2BB10 /* Speaker.swift in Sources */,
1E8C89971F21DC7D00D2BB10 /* Request.swift in Sources */,
1E8C89881F21DC7D00D2BB10 /* OctavAPIError.swift in Sources */,
1E8C89951F21DC7D00D2BB10 /* OctavKit.swift in Sources */,
1E8C89891F21DC7D00D2BB10 /* ParameterHolder.swift in Sources */,
1E8C898C1F21DC7D00D2BB10 /* Conference.swift in Sources */,
1E8C89971F21DC7D00D2BB10 /* Request.swift in Sources */,
1E8C89901F21DC7D00D2BB10 /* Schedule.swift in Sources */,
1E8C89911F21DC7D00D2BB10 /* Session.swift in Sources */,
1E8C898F1F21DC7D00D2BB10 /* Speaker.swift in Sources */,
1E8C89921F21DC7D00D2BB10 /* Sponsor.swift in Sources */,
1E5CE3921F7782C80088F648 /* Staff.swift in Sources */,
1E8C898B1F21DC7D00D2BB10 /* Date+ISO8601.swift in Sources */,
1E8C89961F21DC7D00D2BB10 /* HTTPMethod.swift in Sources */,
1E8C89931F21DC7D00D2BB10 /* Track.swift in Sources */,
1E8C89901F21DC7D00D2BB10 /* Schedule.swift in Sources */,
1E8C898A1F21DC7D00D2BB10 /* Date+components.swift in Sources */,
1E8C89941F21DC7D00D2BB10 /* Venue.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Expand Up @@ -47,11 +47,11 @@ extension Date {
}

extension Date {
fileprivate var components: DateComponents {
private var components: DateComponents {
return calendar.dateComponents([.year, .month, .weekday, .day, .hour, .minute, .second], from: self)
}

fileprivate var calendar: Calendar {
private var calendar: Calendar {
return Calendar(identifier: Calendar.Identifier.gregorian)
}
}
2 changes: 1 addition & 1 deletion OctavKit/OctavKit.swift
Expand Up @@ -11,7 +11,7 @@ public final class OctavKit {

private init() {}

fileprivate static func send<T: Request>(_ request: T, completion: @escaping (Result<T.Response, OctavAPIError>) -> Void) {
private static func send<T: Request>(_ request: T, completion: @escaping (T.Response?, OctavAPIError?) -> Void) {
let urlRequest = request.buildURLRequest()
let task = session.dataTask(with: urlRequest) { (data, response, error) -> Void in
switch (data, response, error) {
Expand Down
File renamed without changes.
File renamed without changes.
@@ -1,4 +1,4 @@
public struct Conference: Codable {
public struct Conference: Codable, CustomStringConvertible, Equatable, Hashable {
private enum CodingKeys: String, CodingKey {
case id
case title
Expand All @@ -20,22 +20,12 @@ public struct Conference: Codable {
public let venues: [Venue]
public let sponsors: [Sponsor]
public let tracks: [Track]
}

extension Conference: CustomStringConvertible {
public var description: String {
return "Conference(id: \(id), title: \(title), about: \(about), contact: \(contact), schedules: \(schedules), " +
"staffs: \(staffs), venues: \(venues), sponsors: \(sponsors), tracks: \(tracks))"
}
}

extension Conference: Equatable {
public static func == (lhs: Conference, rhs: Conference) -> Bool {
return lhs.id == rhs.id
}
}

extension Conference: Hashable {
public var hashValue: Int {
return id.hashValue
}
Expand Down
22 changes: 4 additions & 18 deletions OctavKit/model/Schedule.swift → OctavKit/Response/Schedule.swift
@@ -1,5 +1,5 @@
extension Conference {
public struct Schedule: Codable {
public struct Schedule: Codable, CustomStringConvertible, Equatable, Hashable {
public let id: String
public let open: Date
public let close: Date
Expand All @@ -14,12 +14,10 @@ extension Conference {
public var duration: TimeInterval {
return close.timeIntervalSince(open)
}
}
}

extension Conference.Schedule: CustomStringConvertible {
public var description: String {
return "Schedule(id: \(id), open: \(open), close: \(close))"
public var description: String {
return "Schedule(id: \(id), open: \(open), close: \(close))"
}
}
}

Expand All @@ -32,15 +30,3 @@ extension Conference.Schedule: Comparable {
return lhs.close > rhs.close
}
}

extension Conference.Schedule: Equatable {
public static func == (lhs: Conference.Schedule, rhs: Conference.Schedule) -> Bool {
return lhs.id == rhs.id
}
}

extension Conference.Schedule: Hashable {
public var hashValue: Int {
return id.hashValue
}
}
25 changes: 8 additions & 17 deletions OctavKit/model/Session.swift → OctavKit/Response/Session.swift
@@ -1,6 +1,6 @@
import Foundation

public struct Session: Codable {
public struct Session: Codable, CustomStringConvertible, Equatable, Hashable {
private enum CodingKeys: String, CodingKey {
case id
case room
Expand All @@ -13,7 +13,7 @@ public struct Session: Codable {
case materialLevel = "material_level"
}

public enum Level: String, Codable {
public enum Level: String, Codable, Equatable, Hashable {
case beginner
case intermediate
case advanced
Expand All @@ -32,7 +32,7 @@ public struct Session: Codable {
public var endsOn: Date {
return startsOn.add(second: duration)
}

public init(from decoder: Decoder) throws {
func strictString(_ value: String) -> String? {
if value.isEmpty {
Expand All @@ -53,30 +53,21 @@ public struct Session: Codable {
self.duration = try container.decode(Int.self, forKey: .duration)
self.materialLevel = try container.decode(Level.self, forKey: .materialLevel)
}
}

extension Session: CustomStringConvertible {
public var description: String {
return "Session(id: \(id), room: \(room), speaker: \(speaker), title: \(title), " +
"abstract: \(abstract), memo: \(memo.debugDescription), startsOn: \(startsOn), duration: \(duration), " +
"materialLevel: \(materialLevel.rawValue))"
}
}

extension Session: Comparable {
public static func < (lhs: Session, rhs: Session) -> Bool {
return lhs.startsOn < rhs.startsOn
public var hashValue: Int {
return id.hashValue
}
}

extension Session: Equatable {
public static func == (lhs: Session, rhs: Session) -> Bool {
return lhs.id == rhs.id
}
}

extension Session: Hashable {
public var hashValue: Int {
return id.hashValue
extension Session: Comparable {
public static func < (lhs: Session, rhs: Session) -> Bool {
return lhs.startsOn < rhs.startsOn
}
}
Expand Up @@ -21,10 +21,6 @@ extension Conference {
"lastname: \(lastname.debugDescription), avatarURL: \(avatarURL))"
}

public static func == (lhs: Speaker, rhs: Speaker) -> Bool {
return lhs.id == rhs.id
}

public var hashValue: Int {
return id.hashValue
}
Expand Down
16 changes: 1 addition & 15 deletions OctavKit/model/Sponsor.swift → OctavKit/Response/Sponsor.swift
@@ -1,6 +1,6 @@
import Foundation

public struct Sponsor: Codable {
public struct Sponsor: Codable, CustomStringConvertible, Equatable, Hashable {
private enum CodingKeys: String, CodingKey {
case id
case name
Expand All @@ -14,23 +14,9 @@ public struct Sponsor: Codable {
public let logoURL: URL
public let linkURL: URL
public let groupName: String
}

extension Sponsor: CustomStringConvertible {
public var description: String {
return "Sponsor(id: \(id), name: \(name), logoURL: \(logoURL), " +
"linkURL: \(linkURL), groupName: \(groupName))"
}
}

extension Sponsor: Equatable {
public static func == (lhs: Sponsor, rhs: Sponsor) -> Bool {
return lhs.id == rhs.id
}
}

extension Sponsor: Hashable {
public var hashValue: Int {
return id.hashValue
}
}
4 changes: 0 additions & 4 deletions OctavKit/model/Staff.swift → OctavKit/Response/Staff.swift
Expand Up @@ -22,10 +22,6 @@ extension Conference {
"lastname: \(lastname.debugDescription), avatarURL: \(avatarURL))"
}

public static func == (lhs: Staff, rhs: Staff) -> Bool {
return lhs.id == rhs.id
}

public var hashValue: Int {
return id.hashValue
}
Expand Down
37 changes: 37 additions & 0 deletions OctavKit/Response/Track.swift
@@ -0,0 +1,37 @@
extension Conference {
public struct Track: Codable, CustomStringConvertible, Equatable, Hashable {
private enum CodingKeys: String, CodingKey {
case id
case roomId = "room_id"
case name
}

public let id: String
public let roomId: String
public let name: String

public var description: String {
return "Track(id: \(id), roomId: \(roomId), name: \(name))"
}
}
}

extension Conference.Track {
public struct Room: Codable, CustomStringConvertible, Equatable, Hashable {
private enum CodingKeys: String, CodingKey {
case id
case venueId = "venue_id"
case name
case capacity
}

public let id: String
public let venueId: String
public let name: String
public let capacity: Int

public var description: String {
return "Room(id: \(id), venueId: \(venueId), name: \(name), capacity: \(capacity))"
}
}
}
File renamed without changes.

0 comments on commit f058c25

Please sign in to comment.