add files model

This commit is contained in:
Ryan Nystrom
2017-08-11 23:09:56 -04:00
parent 89699c1661
commit 4c7c3ca27f
4 changed files with 113 additions and 17 deletions

108
Classes/Models/File.swift Normal file
View File

@@ -0,0 +1,108 @@
import Foundation
final class File: NSObject, NSCoding {
struct Keys {
static let status = "status"
static let changes = "changes"
static let filename = "filename"
static let additions = "additions"
static let raw_url = "raw_url"
static let deletions = "deletions"
static let sha = "sha"
static let blob_url = "blob_url"
static let patch = "patch"
static let contents_url = "contents_url"
}
let status: String
let changes: NSNumber
let filename: String
let additions: NSNumber
let raw_url: String
let deletions: NSNumber
let sha: String
let blob_url: String
let patch: String
let contents_url: String
convenience init?(json: [String: Any]?) {
guard let status = json?[Keys.status] as? String else { return nil }
guard let changes = json?[Keys.changes] as? NSNumber else { return nil }
guard let filename = json?[Keys.filename] as? String else { return nil }
guard let additions = json?[Keys.additions] as? NSNumber else { return nil }
guard let raw_url = json?[Keys.raw_url] as? String else { return nil }
guard let deletions = json?[Keys.deletions] as? NSNumber else { return nil }
guard let sha = json?[Keys.sha] as? String else { return nil }
guard let blob_url = json?[Keys.blob_url] as? String else { return nil }
guard let patch = json?[Keys.patch] as? String else { return nil }
guard let contents_url = json?[Keys.contents_url] as? String else { return nil }
self.init(
status: status,
changes: changes,
filename: filename,
additions: additions,
raw_url: raw_url,
deletions: deletions,
sha: sha,
blob_url: blob_url,
patch: patch,
contents_url: contents_url
)
}
init(
status: String,
changes: NSNumber,
filename: String,
additions: NSNumber,
raw_url: String,
deletions: NSNumber,
sha: String,
blob_url: String,
patch: String,
contents_url: String
) {
self.status = status
self.changes = changes
self.filename = filename
self.additions = additions
self.raw_url = raw_url
self.deletions = deletions
self.sha = sha
self.blob_url = blob_url
self.patch = patch
self.contents_url = contents_url
}
convenience init?(coder aDecoder: NSCoder) {
guard let status = aDecoder.decodeObject(forKey: Keys.status) as? String else { return nil }
guard let changes = aDecoder.decodeObject(forKey: Keys.changes) as? NSNumber else { return nil }
guard let filename = aDecoder.decodeObject(forKey: Keys.filename) as? String else { return nil }
guard let additions = aDecoder.decodeObject(forKey: Keys.additions) as? NSNumber else { return nil }
guard let raw_url = aDecoder.decodeObject(forKey: Keys.raw_url) as? String else { return nil }
guard let deletions = aDecoder.decodeObject(forKey: Keys.deletions) as? NSNumber else { return nil }
guard let sha = aDecoder.decodeObject(forKey: Keys.sha) as? String else { return nil }
guard let blob_url = aDecoder.decodeObject(forKey: Keys.blob_url) as? String else { return nil }
guard let patch = aDecoder.decodeObject(forKey: Keys.patch) as? String else { return nil }
guard let contents_url = aDecoder.decodeObject(forKey: Keys.contents_url) as? String else { return nil }
self.init(
status: status,
changes: changes,
filename: filename,
additions: additions,
raw_url: raw_url,
deletions: deletions,
sha: sha,
blob_url: blob_url,
patch: patch,
contents_url: contents_url
)
}
func encode(with aCoder: NSCoder) {
aCoder.encode(status, forKey: Keys.status)
aCoder.encode(changes, forKey: Keys.changes)
aCoder.encode(filename, forKey: Keys.filename)
aCoder.encode(additions, forKey: Keys.additions)
aCoder.encode(raw_url, forKey: Keys.raw_url)
aCoder.encode(deletions, forKey: Keys.deletions)
aCoder.encode(sha, forKey: Keys.sha)
aCoder.encode(blob_url, forKey: Keys.blob_url)
aCoder.encode(patch, forKey: Keys.patch)
aCoder.encode(contents_url, forKey: Keys.contents_url)
}
}

View File

@@ -1,16 +0,0 @@
//
// Secrets.swift
// Freetime
//
// Created by Ryan Nystrom on 5/6/17.
// Copyright © 2017 Ryan Nystrom. All rights reserved.
//
import Foundation
public enum GithubAPI {
static let clientID = "YOUR_CLIENT_ID"
static let clientSecret = "YOUR_CLIENT_SECRET"
}

View File

@@ -22,6 +22,7 @@
290EF56A1F06A821006A2160 /* Notification+NotificationViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 290EF5691F06A7E1006A2160 /* Notification+NotificationViewModel.swift */; };
290EF5761F06BA06006A2160 /* NoNewNotificationsCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 290EF5751F06BA06006A2160 /* NoNewNotificationsCell.swift */; };
290EF5791F06BAF4006A2160 /* NoNewNotificationsSectionController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 290EF5781F06BAF4006A2160 /* NoNewNotificationsSectionController.swift */; };
291929421F3EA8CD0012067B /* File.swift in Sources */ = {isa = PBXBuildFile; fileRef = 291929411F3EA8CD0012067B /* File.swift */; };
292484B81F01CB5C0054FE20 /* SwipeCellKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 292484B71F01CB5C0054FE20 /* SwipeCellKit.framework */; };
292484B91F01CB5C0054FE20 /* SwipeCellKit.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 292484B71F01CB5C0054FE20 /* SwipeCellKit.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
2928C7881F15D7C50000D06D /* IssueRenamedModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2928C7871F15D7C50000D06D /* IssueRenamedModel.swift */; };
@@ -314,6 +315,7 @@
290EF5691F06A7E1006A2160 /* Notification+NotificationViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Notification+NotificationViewModel.swift"; sourceTree = "<group>"; };
290EF5751F06BA06006A2160 /* NoNewNotificationsCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NoNewNotificationsCell.swift; sourceTree = "<group>"; };
290EF5781F06BAF4006A2160 /* NoNewNotificationsSectionController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NoNewNotificationsSectionController.swift; sourceTree = "<group>"; };
291929411F3EA8CD0012067B /* File.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = File.swift; sourceTree = "<group>"; };
292484B71F01CB5C0054FE20 /* SwipeCellKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = SwipeCellKit.framework; sourceTree = BUILT_PRODUCTS_DIR; };
2928C7871F15D7C50000D06D /* IssueRenamedModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IssueRenamedModel.swift; sourceTree = "<group>"; };
2928C7891F15D7E00000D06D /* IssueRenamedCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IssueRenamedCell.swift; sourceTree = "<group>"; };
@@ -988,6 +990,7 @@
children = (
297AE85F1EC0D5C100B44A1F /* App.swift */,
297AE8601EC0D5C100B44A1F /* Authorization.swift */,
291929411F3EA8CD0012067B /* File.swift */,
2963A93A1EE25F6F0066509C /* LabelableFields+IssueLabelModel.swift */,
29C9FDBA1EC65FEE00EE3A52 /* Notification.swift */,
29C9FDBB1EC65FEE00EE3A52 /* Organization.swift */,
@@ -1574,6 +1577,7 @@
298BA09A1EC947FC00B01946 /* SegmentedControlModel.swift in Sources */,
299C06D81F0DD17B00C2828E /* IssueReviewEmptyTailCell.swift in Sources */,
298BA0981EC947F100B01946 /* SegmentedControlSectionController.swift in Sources */,
291929421F3EA8CD0012067B /* File.swift in Sources */,
297A372E1F17018F0081C04E /* IssueRequestCell.swift in Sources */,
292FCB081EDFCC510026635E /* IssueCommentSummaryCell.swift in Sources */,
292FCB211EDFCF870026635E /* IssueReactionCell.swift in Sources */,

View File

@@ -32,7 +32,7 @@
</dict>
</array>
<key>CFBundleVersion</key>
<string>1331</string>
<string>1335</string>
<key>ITSAppUsesNonExemptEncryption</key>
<false/>
<key>LSApplicationQueriesSchemes</key>