Skip to content

Commit 9e5cc7a

Browse files
committed
Lint/whitespace fixes
1 parent f3749b6 commit 9e5cc7a

File tree

2 files changed

+28
-28
lines changed

2 files changed

+28
-28
lines changed

ParseSwift.playground/Pages/1 - Your first Object.xcplaygroundpage/Contents.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ struct GameScore: ParseObject {
3939

4040
//: Your own properties.
4141
var score: Int = 0
42-
43-
//: Optional custom properties need to be marked with @NullableProperty or setting properties to `nil` won't propagate to server
42+
43+
//: Optional custom properties need to be marked with @NullableProperty or
44+
// setting properties to `nil` won't propagate to server
4445
@NullableProperty var gameEndDate: Date?
4546

4647
/*:

Sources/ParseSwift/Coding/NullableProperty.swift

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -20,46 +20,45 @@ import Foundation
2020
@propertyWrapper
2121
public struct NullableProperty<Wrapped> {
2222

23-
public var wrappedValue: Wrapped?
23+
public var wrappedValue: Wrapped?
2424

25-
public init(wrappedValue: Wrapped?) {
26-
self.wrappedValue = wrappedValue
27-
}
25+
public init(wrappedValue: Wrapped?) {
26+
self.wrappedValue = wrappedValue
27+
}
2828
}
2929

3030
extension NullableProperty: Encodable where Wrapped: Encodable {
3131

32-
public func encode(to encoder: Encoder) throws {
33-
var container = encoder.singleValueContainer()
34-
switch wrappedValue {
35-
case .some(let value):
36-
// Standard value
37-
try container.encode(value)
38-
39-
case .none:
40-
// Empty value, encode delete op command
41-
try container.encode(Delete())
42-
}
43-
}
32+
public func encode(to encoder: Encoder) throws {
33+
var container = encoder.singleValueContainer()
34+
switch wrappedValue {
35+
case .some(let value):
36+
try container.encode(value)
37+
38+
case .none:
39+
try container.encode(Delete())
40+
}
41+
}
4442
}
4543

4644
extension NullableProperty: Decodable where Wrapped: Decodable {
4745

48-
public init(from decoder: Decoder) throws {
49-
let container = try decoder.singleValueContainer()
50-
// Values coming from server won't have the delete operation, so we can just check if it's a null value and then decode normally.
51-
if !container.decodeNil() {
52-
wrappedValue = try container.decode(Wrapped.self)
53-
}
54-
}
46+
public init(from decoder: Decoder) throws {
47+
let container = try decoder.singleValueContainer()
48+
if !container.decodeNil() {
49+
wrappedValue = try container.decode(Wrapped.self)
50+
}
51+
}
5552
}
5653

5754
extension NullableProperty: Hashable where Wrapped: Hashable { }
5855
extension NullableProperty: Equatable where Wrapped: Equatable { }
5956

6057
extension KeyedDecodingContainer {
6158

62-
public func decode<Wrapped>(_ type: NullableProperty<Wrapped>.Type, forKey key: KeyedDecodingContainer<K>.Key) throws -> NullableProperty<Wrapped> where Wrapped: Decodable {
63-
return try decodeIfPresent(NullableProperty<Wrapped>.self, forKey: key) ?? NullableProperty<Wrapped>(wrappedValue: nil)
64-
}
59+
public func decode<Wrapped>(_ type: NullableProperty<Wrapped>.Type, forKey key: KeyedDecodingContainer<K>.Key)
60+
throws -> NullableProperty<Wrapped> where Wrapped: Decodable {
61+
return try decodeIfPresent(NullableProperty<Wrapped>.self, forKey: key) ??
62+
NullableProperty<Wrapped>(wrappedValue: nil)
63+
}
6564
}

0 commit comments

Comments
 (0)