-
Notifications
You must be signed in to change notification settings - Fork 26
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
Add support for earlier OS versions + Change stream line separator to CRLF #59
base: main
Are you sure you want to change the base?
Conversation
Sources/Polyfill.swift
Outdated
@@ -0,0 +1,118 @@ | |||
import Foundation | |||
|
|||
extension Date { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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()`
}
}
Sources/Polyfill.swift
Outdated
} | ||
} | ||
|
||
struct _AsyncBytes: AsyncSequence { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
, butAsyncLineSequence
interprets 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
.