Skip to content

Add support for earlier OS versions + Change stream line separator to CRLF - #59

Open
MMP0 wants to merge 4 commits into
daneden:mainfrom
MMP0:main
Open

Add support for earlier OS versions + Change stream line separator to CRLF#59
MMP0 wants to merge 4 commits into
daneden:mainfrom
MMP0:main

Conversation

@MMP0

@MMP0 MMP0 commented Nov 3, 2022

Copy link
Copy Markdown

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.

Comment thread Sources/Polyfill.swift Outdated
@@ -0,0 +1,118 @@
import Foundation

extension Date {

Copy link
Copy Markdown

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.

Comment thread Sources/Polyfill.swift Outdated

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

Copy link
Copy Markdown

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

Comment thread Sources/Polyfill.swift
}
}

struct _AsyncBytes: AsyncSequence {

Copy link
Copy Markdown

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

MMP0 commented Nov 22, 2022

Copy link
Copy Markdown
Author

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.

2 participants