@@ -42,7 +42,7 @@ import ValueCoding
4242 - see: PKPaymentSummaryItemType
4343 */
4444public enum PaymentSummaryItemType : Int {
45- case Final = 1 , Pending
45+ case final = 1 , pending
4646}
4747
4848/**
@@ -55,7 +55,7 @@ public enum PaymentSummaryItemType: Int {
5555 The money type must use `NSDecimalNumber` storage type, and correctly
5656 conform to `ValueCoding`.
5757 */
58- public struct PaymentSummaryItem < Cost: MoneyType where Cost. DecimalStorageType == NSDecimalNumber , Cost. Coder: NSCoding , Cost. Coder. ValueType == Cost > : Hashable , ValueCoding {
58+ public struct PaymentSummaryItem < Cost: MoneyType > : Hashable , ValueCoding where Cost. DecimalStorageType == NSDecimalNumber , Cost. Coder: NSCoding , Cost. Coder. Value == Cost {
5959
6060 /// The ValueCoding Coder type
6161 public typealias Coder = PaymentSummaryItemCoder < Cost >
@@ -100,13 +100,13 @@ public struct PaymentSummaryItem<Cost: MoneyType where Cost.DecimalStorageType =
100100 - parameter type: the value for the `type` property.
101101 - returns: a summary item with a given label, cost and type.
102102 */
103- public init ( label: String , cost: Cost , type: PaymentSummaryItemType = . Final ) {
103+ public init ( label: String , cost: Cost , type: PaymentSummaryItemType = . final ) {
104104 self . label = label
105105 self . type = type
106106 switch type {
107- case . Final :
107+ case . final :
108108 self . cost = cost
109- case . Pending :
109+ case . pending :
110110 self . cost = 0
111111 }
112112 }
@@ -119,7 +119,7 @@ extension PaymentSummaryItem {
119119 - parameter newLabel: the value for the `label` property in an item copy
120120 - returns: a summary item with a new label value, and previously set cost and type.
121121 */
122- public func setLabel ( newLabel: String ) -> PaymentSummaryItem {
122+ public func set ( label newLabel: String ) -> PaymentSummaryItem {
123123 return PaymentSummaryItem ( label: newLabel, cost: cost, type: type)
124124 }
125125
@@ -128,7 +128,7 @@ extension PaymentSummaryItem {
128128 - parameter newCost: the value for the `cost` property in an item copy
129129 - returns: a summary item with a new cost value, and previously set label and type.
130130 */
131- public func setCost ( newCost: Cost ) -> PaymentSummaryItem {
131+ public func set ( cost newCost: Cost ) -> PaymentSummaryItem {
132132 return PaymentSummaryItem ( label: label, cost: newCost, type: type)
133133 }
134134
@@ -137,15 +137,15 @@ extension PaymentSummaryItem {
137137 - parameter newType: the value for the `type` property in an item copy
138138 - returns: a summary item with a new type value, and previously set label and cost.
139139 */
140- public func setType ( newType: PaymentSummaryItemType ) -> PaymentSummaryItem {
140+ public func set ( type newType: PaymentSummaryItemType ) -> PaymentSummaryItem {
141141 return PaymentSummaryItem ( label: label, cost: cost, type: newType)
142142 }
143143}
144144
145145/**
146146 Coding adaptor for `PaymentSummaryItem`.
147147*/
148- public final class PaymentSummaryItemCoder < Cost: MoneyType where Cost. DecimalStorageType == NSDecimalNumber , Cost. Coder: NSCoding , Cost. Coder. ValueType == Cost > : NSObject , NSCoding , CodingType {
148+ public final class PaymentSummaryItemCoder < Cost: MoneyType > : NSObject , NSCoding , CodingProtocol where Cost. DecimalStorageType == NSDecimalNumber , Cost. Coder: NSCoding , Cost. Coder. Value == Cost {
149149
150150 public let value : PaymentSummaryItem < Cost >
151151
@@ -154,16 +154,16 @@ public final class PaymentSummaryItemCoder<Cost: MoneyType where Cost.DecimalSto
154154 }
155155
156156 public init ? ( coder aDecoder: NSCoder ) {
157- let cost = Cost . decode ( aDecoder. decodeObjectForKey ( " cost " ) )
158- let label = aDecoder. decodeObjectForKey ( " label " ) as? String
159- let type = PaymentSummaryItemType ( rawValue: aDecoder. decodeIntegerForKey ( " type " ) )
157+ let cost = Cost . decode ( aDecoder. decodeObject ( forKey : " cost " ) as AnyObject ? )
158+ let label = aDecoder. decodeObject ( forKey : " label " ) as? String
159+ let type = PaymentSummaryItemType ( rawValue: aDecoder. decodeInteger ( forKey : " type " ) )
160160 value = PaymentSummaryItem ( label: label!, cost: cost!, type: type!)
161161 }
162162
163- public func encodeWithCoder ( aCoder: NSCoder ) {
164- aCoder. encodeObject ( value. label, forKey: " label " )
165- aCoder. encodeObject ( value. cost. encoded, forKey: " cost " )
166- aCoder. encodeInteger ( value. type. rawValue, forKey: " type " )
163+ public func encode ( with aCoder: NSCoder ) {
164+ aCoder. encode ( value. label, forKey: " label " )
165+ aCoder. encode ( value. cost. encoded, forKey: " cost " )
166+ aCoder. encode ( value. type. rawValue, forKey: " type " )
167167 }
168168}
169169
@@ -174,17 +174,17 @@ internal extension PKPaymentSummaryItemType {
174174
175175 init ( paymentSummaryItemType: PaymentSummaryItemType ) {
176176 switch paymentSummaryItemType {
177- case . Final :
178- self = . Final
179- case . Pending :
180- self = . Pending
177+ case . final :
178+ self = . final
179+ case . pending :
180+ self = . pending
181181 }
182182 }
183183}
184184
185185internal extension PKPaymentSummaryItem {
186186
187- convenience init < Cost: MoneyType where Cost. DecimalStorageType == NSDecimalNumber > ( paymentSummaryItem : PaymentSummaryItem < Cost > ) {
187+ convenience init < Cost: MoneyType > ( paymentSummaryItem : PaymentSummaryItem < Cost > ) where Cost. DecimalStorageType == NSDecimalNumber {
188188 self . init ( )
189189 amount = paymentSummaryItem. amount
190190 label = paymentSummaryItem. label
@@ -209,19 +209,19 @@ public extension PKPaymentRequest {
209209 - parameter sellerName: a `String` which is used in the total cost summary item.
210210 - returns: a `PKPaymentRequest` which has its payment summary items and currency code set.
211211 */
212- convenience init < Cost: MoneyType where Cost. DecimalStorageType == NSDecimalNumber , Cost. Coder: NSCoding , Cost. Coder. ValueType == Cost > ( items : [ PaymentSummaryItem < Cost > ] , sellerName : String ) {
212+ convenience init < Cost: MoneyType > ( items : [ PaymentSummaryItem < Cost > ] , sellerName : String ) where Cost. DecimalStorageType == NSDecimalNumber , Cost. Coder: NSCoding , Cost. Coder. Value == Cost {
213213 self . init ( )
214214 currencyCode = Cost . Currency. code
215215 var items = items
216- let total = items. map { $0. cost } . reduce ( 0 , combine : + )
216+ let total = items. map { $0. cost } . reduce ( 0 , + )
217217 items. append ( PaymentSummaryItem ( label: sellerName, cost: total) )
218218 paymentSummaryItems = items. map { PKPaymentSummaryItem ( paymentSummaryItem: $0) }
219219 }
220220}
221221
222222// MARK: - Equality
223223
224- public func == < Cost: MoneyType where Cost . DecimalStorageType == NSDecimalNumber > ( lhs: PaymentSummaryItem < Cost > , rhs: PaymentSummaryItem < Cost > ) -> Bool {
224+ public func == < Cost: MoneyType > ( lhs: PaymentSummaryItem < Cost > , rhs: PaymentSummaryItem < Cost > ) -> Bool where Cost . DecimalStorageType == NSDecimalNumber {
225225 return lhs. cost == rhs. cost && lhs. label == rhs. label && lhs. type == rhs. type
226226}
227227
0 commit comments