-
-
Notifications
You must be signed in to change notification settings - Fork 70
Renaming, Reorganization, PrimitiveObjectStore, new ParseEncoder #13
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
Merged
Merged
Changes from 8 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
bea067c
move stuff around
pranjalsatija 77c84dc
rename things
pranjalsatija 3e6092d
organize ParseObject and ParseUser
pranjalsatija ef37863
organize Coding
pranjalsatija 00f4622
add IDEWorkspaceChecks
pranjalsatija 3547627
add PrimitiveObjectStore and friends
pranjalsatija bdfd709
simplify ParseEncoder
pranjalsatija 1819601
remove force unwrap
pranjalsatija d876bd1
use ParseError
pranjalsatija b5c5259
retry build
pranjalsatija 69b2136
Merge branch 'master' of https://github.com/parse-community/Parse-Swi…
pranjalsatija 2cd23a9
finish merging
pranjalsatija 1070fe9
add hasSameObjectId
pranjalsatija f209e2e
add rough NewParseEncoder
pranjalsatija 9a74666
better
pranjalsatija 72684f2
more improvements
pranjalsatija 4cb2019
finished for now
pranjalsatija 38021ae
add key skipping
pranjalsatija e41acdf
remove old ParseEncoder
pranjalsatija e48f242
fix tests
pranjalsatija 2e2a164
add MARK comments to ParseEncoder
pranjalsatija bd09c9e
fix target membership
pranjalsatija e24503f
Merge branch 'master' of https://github.com/parse-community/Parse-Swi…
pranjalsatija c5fd3a8
finish merging master
pranjalsatija 55f0d7d
add array support to ParseEncoder; replace _ with <root>
pranjalsatija 81c2cbd
update file credits
pranjalsatija 18c08a5
fix more tests
pranjalsatija 8189db8
address PR feedback
pranjalsatija c28829c
add ParseEncoderTests
pranjalsatija f621266
bump test host deployment target
pranjalsatija a8c43ac
add availability check
pranjalsatija ee7e1fe
increase coverage target
pranjalsatija File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>IDEDidComputeMac32BitWarning</key> | ||
<true/> | ||
</dict> | ||
</plist> |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or 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,37 @@ | ||
// | ||
// File.swift | ||
pranjalsatija marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// | ||
pranjalsatija marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// | ||
// Created by Pranjal Satija on 7/19/20. | ||
// | ||
|
||
import Foundation | ||
|
||
// MARK: Date | ||
internal extension Date { | ||
func parseFormatted() -> String { | ||
return ParseCoding.dateFormatter.string(from: self) | ||
} | ||
|
||
var parseRepresentation: [String: String] { | ||
return ["__type": "Date", "iso": parseFormatted()] | ||
} | ||
} | ||
|
||
// MARK: JSONEncoder | ||
extension JSONEncoder { | ||
func encodeAsString<T>(_ value: T) throws -> String where T: Encodable { | ||
guard let string = String(data: try encode(value), encoding: .utf8) else { | ||
throw ParseError(code: .unknownError, message: "Unable to encode object...") | ||
} | ||
|
||
return string | ||
} | ||
} | ||
|
||
// MARK: ParseObject | ||
internal extension ParseObject { | ||
func getEncoder() -> ParseEncoder { | ||
return ParseCoding.parseEncoder() | ||
} | ||
} |
This file contains hidden or 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,80 @@ | ||
// | ||
// ParseObjectType.swift | ||
pranjalsatija marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// ParseSwift | ||
// | ||
// Created by Florent Vilmart on 17-07-24. | ||
// Copyright © 2017 Parse. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
// MARK: ParseCoding | ||
internal enum ParseCoding {} | ||
|
||
// MARK: Coders | ||
extension ParseCoding { | ||
private static let forbiddenKeys = Set(["createdAt", "updatedAt", "objectId", "className"]) | ||
|
||
static func jsonEncoder() -> JSONEncoder { | ||
let encoder = JSONEncoder() | ||
encoder.dateEncodingStrategy = dateEncodingStrategy | ||
return encoder | ||
} | ||
|
||
static func jsonDecoder() -> JSONDecoder { | ||
let encoder = JSONDecoder() | ||
pranjalsatija marked this conversation as resolved.
Show resolved
Hide resolved
|
||
encoder.dateDecodingStrategy = dateDecodingStrategy | ||
return encoder | ||
} | ||
|
||
static func parseEncoder() -> ParseEncoder { | ||
let encoder = ParseEncoder() | ||
encoder.dateEncodingStrategy = dateEncodingStrategy | ||
encoder.shouldEncodeKey = { (key, path) -> Bool in | ||
if path.count == 0 // top level | ||
&& Self.forbiddenKeys.contains(key) { | ||
return false | ||
} | ||
return true | ||
} | ||
|
||
return encoder | ||
} | ||
} | ||
|
||
// MARK: Dates | ||
extension ParseCoding { | ||
enum DateEncodingKeys: String, CodingKey { | ||
case iso | ||
case type = "__type" | ||
} | ||
|
||
static let dateFormatter: DateFormatter = { | ||
var dateFormatter = DateFormatter() | ||
dateFormatter.locale = Locale(identifier: "") | ||
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" | ||
return dateFormatter | ||
}() | ||
|
||
static let dateEncodingStrategy: JSONEncoder.DateEncodingStrategy = .custom({ (date, enc) in | ||
var container = enc.container(keyedBy: DateEncodingKeys.self) | ||
try container.encode("Date", forKey: .type) | ||
let dateString = dateFormatter.string(from: date) | ||
try container.encode(dateString, forKey: .iso) | ||
}) | ||
|
||
static let dateDecodingStrategy: JSONDecoder.DateDecodingStrategy = .custom({ (dec) -> Date in | ||
pranjalsatija marked this conversation as resolved.
Show resolved
Hide resolved
|
||
do { | ||
let container = try dec.singleValueContainer() | ||
let decodedString = try container.decode(String.self) | ||
return dateFormatter.date(from: decodedString)! | ||
pranjalsatija marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} catch let error { | ||
let container = try dec.container(keyedBy: DateEncodingKeys.self) | ||
if let decoded = try container.decodeIfPresent(String.self, forKey: .iso) { | ||
return dateFormatter.date(from: decoded)! | ||
pranjalsatija marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
|
||
throw ParseError(code: .unknownError, message: "unable to decode") | ||
}) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.