Skip to content

Commit

Permalink
[swift5] Fix Xcode 16 compilation crash with Extensions.swift generat…
Browse files Browse the repository at this point in the history
…ion (#19564)

* Update Extensions template for Swift5 generation

* update samples
  • Loading branch information
lilidotshi authored Sep 11, 2024
1 parent 1658264 commit 0e763b0
Show file tree
Hide file tree
Showing 18 changed files with 108 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,12 @@ extension KeyedEncodingContainerProtocol {
}

{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} mutating func encode(_ value: Decimal, forKey key: Self.Key) throws {
var mutableValue = value
let stringValue = NSDecimalString(&mutableValue, Locale(identifier: "en_US"))
try encode(stringValue, forKey: key)
let decimalNumber = NSDecimalNumber(decimal: value)
let numberFormatter = NumberFormatter()
numberFormatter.numberStyle = .decimal
numberFormatter.locale = Locale(identifier: "en_US")
let formattedString = numberFormatter.string(from: decimalNumber) ?? "\(value)"
try encode(formattedString, forKey: key)
}

{{#nonPublicApi}}internal{{/nonPublicApi}}{{^nonPublicApi}}public{{/nonPublicApi}} mutating func encodeIfPresent(_ value: Decimal?, forKey key: Self.Key) throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,12 @@ extension KeyedEncodingContainerProtocol {
}

public mutating func encode(_ value: Decimal, forKey key: Self.Key) throws {
var mutableValue = value
let stringValue = NSDecimalString(&mutableValue, Locale(identifier: "en_US"))
try encode(stringValue, forKey: key)
let decimalNumber = NSDecimalNumber(decimal: value)
let numberFormatter = NumberFormatter()
numberFormatter.numberStyle = .decimal
numberFormatter.locale = Locale(identifier: "en_US")
let formattedString = numberFormatter.string(from: decimalNumber) ?? "\(value)"
try encode(formattedString, forKey: key)
}

public mutating func encodeIfPresent(_ value: Decimal?, forKey key: Self.Key) throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,12 @@ extension KeyedEncodingContainerProtocol {
}

public mutating func encode(_ value: Decimal, forKey key: Self.Key) throws {
var mutableValue = value
let stringValue = NSDecimalString(&mutableValue, Locale(identifier: "en_US"))
try encode(stringValue, forKey: key)
let decimalNumber = NSDecimalNumber(decimal: value)
let numberFormatter = NumberFormatter()
numberFormatter.numberStyle = .decimal
numberFormatter.locale = Locale(identifier: "en_US")
let formattedString = numberFormatter.string(from: decimalNumber) ?? "\(value)"
try encode(formattedString, forKey: key)
}

public mutating func encodeIfPresent(_ value: Decimal?, forKey key: Self.Key) throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,12 @@ extension KeyedEncodingContainerProtocol {
}

public mutating func encode(_ value: Decimal, forKey key: Self.Key) throws {
var mutableValue = value
let stringValue = NSDecimalString(&mutableValue, Locale(identifier: "en_US"))
try encode(stringValue, forKey: key)
let decimalNumber = NSDecimalNumber(decimal: value)
let numberFormatter = NumberFormatter()
numberFormatter.numberStyle = .decimal
numberFormatter.locale = Locale(identifier: "en_US")
let formattedString = numberFormatter.string(from: decimalNumber) ?? "\(value)"
try encode(formattedString, forKey: key)
}

public mutating func encodeIfPresent(_ value: Decimal?, forKey key: Self.Key) throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,12 @@ extension KeyedEncodingContainerProtocol {
}

public mutating func encode(_ value: Decimal, forKey key: Self.Key) throws {
var mutableValue = value
let stringValue = NSDecimalString(&mutableValue, Locale(identifier: "en_US"))
try encode(stringValue, forKey: key)
let decimalNumber = NSDecimalNumber(decimal: value)
let numberFormatter = NumberFormatter()
numberFormatter.numberStyle = .decimal
numberFormatter.locale = Locale(identifier: "en_US")
let formattedString = numberFormatter.string(from: decimalNumber) ?? "\(value)"
try encode(formattedString, forKey: key)
}

public mutating func encodeIfPresent(_ value: Decimal?, forKey key: Self.Key) throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,12 @@ extension KeyedEncodingContainerProtocol {
}

public mutating func encode(_ value: Decimal, forKey key: Self.Key) throws {
var mutableValue = value
let stringValue = NSDecimalString(&mutableValue, Locale(identifier: "en_US"))
try encode(stringValue, forKey: key)
let decimalNumber = NSDecimalNumber(decimal: value)
let numberFormatter = NumberFormatter()
numberFormatter.numberStyle = .decimal
numberFormatter.locale = Locale(identifier: "en_US")
let formattedString = numberFormatter.string(from: decimalNumber) ?? "\(value)"
try encode(formattedString, forKey: key)
}

public mutating func encodeIfPresent(_ value: Decimal?, forKey key: Self.Key) throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,12 @@ extension KeyedEncodingContainerProtocol {
}

public mutating func encode(_ value: Decimal, forKey key: Self.Key) throws {
var mutableValue = value
let stringValue = NSDecimalString(&mutableValue, Locale(identifier: "en_US"))
try encode(stringValue, forKey: key)
let decimalNumber = NSDecimalNumber(decimal: value)
let numberFormatter = NumberFormatter()
numberFormatter.numberStyle = .decimal
numberFormatter.locale = Locale(identifier: "en_US")
let formattedString = numberFormatter.string(from: decimalNumber) ?? "\(value)"
try encode(formattedString, forKey: key)
}

public mutating func encodeIfPresent(_ value: Decimal?, forKey key: Self.Key) throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,12 @@ extension KeyedEncodingContainerProtocol {
}

public mutating func encode(_ value: Decimal, forKey key: Self.Key) throws {
var mutableValue = value
let stringValue = NSDecimalString(&mutableValue, Locale(identifier: "en_US"))
try encode(stringValue, forKey: key)
let decimalNumber = NSDecimalNumber(decimal: value)
let numberFormatter = NumberFormatter()
numberFormatter.numberStyle = .decimal
numberFormatter.locale = Locale(identifier: "en_US")
let formattedString = numberFormatter.string(from: decimalNumber) ?? "\(value)"
try encode(formattedString, forKey: key)
}

public mutating func encodeIfPresent(_ value: Decimal?, forKey key: Self.Key) throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,12 @@ extension KeyedEncodingContainerProtocol {
}

internal mutating func encode(_ value: Decimal, forKey key: Self.Key) throws {
var mutableValue = value
let stringValue = NSDecimalString(&mutableValue, Locale(identifier: "en_US"))
try encode(stringValue, forKey: key)
let decimalNumber = NSDecimalNumber(decimal: value)
let numberFormatter = NumberFormatter()
numberFormatter.numberStyle = .decimal
numberFormatter.locale = Locale(identifier: "en_US")
let formattedString = numberFormatter.string(from: decimalNumber) ?? "\(value)"
try encode(formattedString, forKey: key)
}

internal mutating func encodeIfPresent(_ value: Decimal?, forKey key: Self.Key) throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,12 @@ extension KeyedEncodingContainerProtocol {
}

public mutating func encode(_ value: Decimal, forKey key: Self.Key) throws {
var mutableValue = value
let stringValue = NSDecimalString(&mutableValue, Locale(identifier: "en_US"))
try encode(stringValue, forKey: key)
let decimalNumber = NSDecimalNumber(decimal: value)
let numberFormatter = NumberFormatter()
numberFormatter.numberStyle = .decimal
numberFormatter.locale = Locale(identifier: "en_US")
let formattedString = numberFormatter.string(from: decimalNumber) ?? "\(value)"
try encode(formattedString, forKey: key)
}

public mutating func encodeIfPresent(_ value: Decimal?, forKey key: Self.Key) throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,12 @@ extension KeyedEncodingContainerProtocol {
}

public mutating func encode(_ value: Decimal, forKey key: Self.Key) throws {
var mutableValue = value
let stringValue = NSDecimalString(&mutableValue, Locale(identifier: "en_US"))
try encode(stringValue, forKey: key)
let decimalNumber = NSDecimalNumber(decimal: value)
let numberFormatter = NumberFormatter()
numberFormatter.numberStyle = .decimal
numberFormatter.locale = Locale(identifier: "en_US")
let formattedString = numberFormatter.string(from: decimalNumber) ?? "\(value)"
try encode(formattedString, forKey: key)
}

public mutating func encodeIfPresent(_ value: Decimal?, forKey key: Self.Key) throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,12 @@ extension KeyedEncodingContainerProtocol {
}

public mutating func encode(_ value: Decimal, forKey key: Self.Key) throws {
var mutableValue = value
let stringValue = NSDecimalString(&mutableValue, Locale(identifier: "en_US"))
try encode(stringValue, forKey: key)
let decimalNumber = NSDecimalNumber(decimal: value)
let numberFormatter = NumberFormatter()
numberFormatter.numberStyle = .decimal
numberFormatter.locale = Locale(identifier: "en_US")
let formattedString = numberFormatter.string(from: decimalNumber) ?? "\(value)"
try encode(formattedString, forKey: key)
}

public mutating func encodeIfPresent(_ value: Decimal?, forKey key: Self.Key) throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,12 @@ extension KeyedEncodingContainerProtocol {
}

public mutating func encode(_ value: Decimal, forKey key: Self.Key) throws {
var mutableValue = value
let stringValue = NSDecimalString(&mutableValue, Locale(identifier: "en_US"))
try encode(stringValue, forKey: key)
let decimalNumber = NSDecimalNumber(decimal: value)
let numberFormatter = NumberFormatter()
numberFormatter.numberStyle = .decimal
numberFormatter.locale = Locale(identifier: "en_US")
let formattedString = numberFormatter.string(from: decimalNumber) ?? "\(value)"
try encode(formattedString, forKey: key)
}

public mutating func encodeIfPresent(_ value: Decimal?, forKey key: Self.Key) throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,12 @@ extension KeyedEncodingContainerProtocol {
}

public mutating func encode(_ value: Decimal, forKey key: Self.Key) throws {
var mutableValue = value
let stringValue = NSDecimalString(&mutableValue, Locale(identifier: "en_US"))
try encode(stringValue, forKey: key)
let decimalNumber = NSDecimalNumber(decimal: value)
let numberFormatter = NumberFormatter()
numberFormatter.numberStyle = .decimal
numberFormatter.locale = Locale(identifier: "en_US")
let formattedString = numberFormatter.string(from: decimalNumber) ?? "\(value)"
try encode(formattedString, forKey: key)
}

public mutating func encodeIfPresent(_ value: Decimal?, forKey key: Self.Key) throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,12 @@ extension KeyedEncodingContainerProtocol {
}

public mutating func encode(_ value: Decimal, forKey key: Self.Key) throws {
var mutableValue = value
let stringValue = NSDecimalString(&mutableValue, Locale(identifier: "en_US"))
try encode(stringValue, forKey: key)
let decimalNumber = NSDecimalNumber(decimal: value)
let numberFormatter = NumberFormatter()
numberFormatter.numberStyle = .decimal
numberFormatter.locale = Locale(identifier: "en_US")
let formattedString = numberFormatter.string(from: decimalNumber) ?? "\(value)"
try encode(formattedString, forKey: key)
}

public mutating func encodeIfPresent(_ value: Decimal?, forKey key: Self.Key) throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,12 @@ extension KeyedEncodingContainerProtocol {
}

public mutating func encode(_ value: Decimal, forKey key: Self.Key) throws {
var mutableValue = value
let stringValue = NSDecimalString(&mutableValue, Locale(identifier: "en_US"))
try encode(stringValue, forKey: key)
let decimalNumber = NSDecimalNumber(decimal: value)
let numberFormatter = NumberFormatter()
numberFormatter.numberStyle = .decimal
numberFormatter.locale = Locale(identifier: "en_US")
let formattedString = numberFormatter.string(from: decimalNumber) ?? "\(value)"
try encode(formattedString, forKey: key)
}

public mutating func encodeIfPresent(_ value: Decimal?, forKey key: Self.Key) throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,12 @@ extension KeyedEncodingContainerProtocol {
}

public mutating func encode(_ value: Decimal, forKey key: Self.Key) throws {
var mutableValue = value
let stringValue = NSDecimalString(&mutableValue, Locale(identifier: "en_US"))
try encode(stringValue, forKey: key)
let decimalNumber = NSDecimalNumber(decimal: value)
let numberFormatter = NumberFormatter()
numberFormatter.numberStyle = .decimal
numberFormatter.locale = Locale(identifier: "en_US")
let formattedString = numberFormatter.string(from: decimalNumber) ?? "\(value)"
try encode(formattedString, forKey: key)
}

public mutating func encodeIfPresent(_ value: Decimal?, forKey key: Self.Key) throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,12 @@ extension KeyedEncodingContainerProtocol {
}

public mutating func encode(_ value: Decimal, forKey key: Self.Key) throws {
var mutableValue = value
let stringValue = NSDecimalString(&mutableValue, Locale(identifier: "en_US"))
try encode(stringValue, forKey: key)
let decimalNumber = NSDecimalNumber(decimal: value)
let numberFormatter = NumberFormatter()
numberFormatter.numberStyle = .decimal
numberFormatter.locale = Locale(identifier: "en_US")
let formattedString = numberFormatter.string(from: decimalNumber) ?? "\(value)"
try encode(formattedString, forKey: key)
}

public mutating func encodeIfPresent(_ value: Decimal?, forKey key: Self.Key) throws {
Expand Down

0 comments on commit 0e763b0

Please sign in to comment.