Skip to content
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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

MMP0
Copy link

@MMP0 MMP0 commented Nov 3, 2022

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, but AsyncLineSequence 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 created AsyncCRLFLineSequence.

@@ -0,0 +1,118 @@
import Foundation

extension Date {

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.


extension Date {
func _ISO8601Format() -> String {
if #available(iOS 15.0, macOS 12.0, *) {

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()`
  }
}

}
}

struct _AsyncBytes: AsyncSequence {

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.

@MMP0
Copy link
Author

MMP0 commented Nov 22, 2022

Thank you for pointing those out. I’ve fixed them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants