-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create CopyCellType and replace usages of CopyCellView with it (#129)
- Loading branch information
1 parent
81105ac
commit 721d2d1
Showing
35 changed files
with
784 additions
and
464 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// | ||
// Encodable.swift | ||
// ec3730 | ||
// | ||
// Created by Zachary Gorak on 12/29/22. | ||
// Copyright © 2022 Zachary Gorak. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
extension Encodable { | ||
var dictionary: [String: Any]? { | ||
guard let data = try? JSONEncoder().encode(self) else { return nil } | ||
return (try? JSONSerialization.jsonObject(with: data, options: .allowFragments)).flatMap { $0 as? [String: Any] } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import UIKit | ||
|
||
enum UIImageDecodingError: Error { | ||
case unableToCreateImage | ||
case unableToGetImageData | ||
} | ||
|
||
public extension Decodable where Self: UIImage { | ||
init(from decoder: Decoder) throws { | ||
let container = try decoder.singleValueContainer() | ||
let data = try container.decode(Data.self) | ||
if let image = Self(data: data) { | ||
self = image | ||
} | ||
throw UIImageDecodingError.unableToCreateImage | ||
} | ||
} | ||
|
||
public extension Encodable where Self: UIImage { | ||
func encode(to encoder: Encoder) throws { | ||
var container = encoder.singleValueContainer() | ||
if let data = pngData() { | ||
try container.encode(data) | ||
} else if let data = jpegData(compressionQuality: 1.0) { | ||
try container.encode(data) | ||
} | ||
throw UIImageDecodingError.unableToGetImageData | ||
} | ||
} | ||
|
||
extension UIImage: Codable {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.