Add support for earlier OS versions + Change stream line separator to CRLF#59
Add support for earlier OS versions + Change stream line separator to CRLF#59MMP0 wants to merge 4 commits intodaneden:mainfrom
Conversation
Sources/Polyfill.swift
Outdated
| @@ -0,0 +1,118 @@ | |||
| import Foundation | |||
|
|
|||
| extension Date { | |||
There was a problem hiding this comment.
Personally, I would put extensions & polyfills each in their own file based on what type they're extending, e.g. DateExtensions.swift (common Swift style), Date+TwiftExtensions.swift (older Obj-C style), or following the existing naming of files in Twift, Date++.swift , or maybe Date+Polyfill.swift considering the use-case.
Sources/Polyfill.swift
Outdated
|
|
||
| extension Date { | ||
| func _ISO8601Format() -> String { | ||
| if #available(iOS 15.0, macOS 12.0, *) { |
There was a problem hiding this comment.
You can wrap functions & structs in available (by using @available instead of #available), so they can have the same name as Apple's identifiers, but not conflict with them on newer OSes.
E.G. Change this:
extension Date {
func _ISO8601Format() -> String {
if #available(iOS 15.0, macOS 12.0, *) {
…
}
}
}to this:
@available(iOS 15.0, macOS 12.0, *)
extension Date {
func ISO8601Format() -> String {
… // only your custom implementation here; no need to call out to `ISO8601Format()`
}
}| } | ||
| } | ||
|
|
||
| struct _AsyncBytes: AsyncSequence { |
There was a problem hiding this comment.
Likewise for AsyncBytes regarding the @available(…) attribute comments above.
|
Thank you for pointing those out. I’ve fixed them. |
Lower the minimum supported OS versions to macOS 10.15 and iOS 13, the lowest versions that support Swift Concurrency.
Also I noticed an issue while creating a polyfill: the Twitter developer page mentions that the line separator in the streaming API is
\r\n, butAsyncLineSequenceinterprets CR (\r), LF (\n), CRLF (\r\n), NEL (\u{85}), LS (\u{2028}) and PS (\u{2029}) as line separators. This could potentially cause problems with tweets containing these characters. So I createdAsyncCRLFLineSequence.