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

OS version availability checks to resolve deprecation warnings #736

Merged
merged 3 commits into from Oct 19, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion Source/platform/iOS/MDisplayLink_iOS.swift
Expand Up @@ -23,7 +23,11 @@ class MDisplayLink: MDisplayLinkProtocol {
self.onUpdate = onUpdate

displayLink = CADisplayLink(target: self, selector: #selector(updateHandler))
displayLink?.frameInterval = 1
if #available(iOS 10.0, *) {
displayLink?.preferredFramesPerSecond = 1
} else {
displayLink?.frameInterval = 1
}
displayLink?.add(to: RunLoop.current, forMode: RunLoop.Mode.default)
}

Expand Down
31 changes: 23 additions & 8 deletions Source/svg/SVGParser.swift
Expand Up @@ -544,14 +544,14 @@ open class SVGParser {

stopParse: while !scanner.isAtEnd {
guard let attributeName = scanner.scannedCharacters(from: .transformationAttributeCharacters),
scanner.scanString("(", into: nil),
scanner.scannedString("(") != nil,
let valuesString = scanner.scannedUpToString(")"),
scanner.scanString(")", into: nil) else {
scanner.scannedString(")") != nil else {
break stopParse
}

// Skip an optional comma after ")".
_ = scanner.scanString(",", into: nil)
_ = scanner.scannedString(",")

let values = parseTransformValues(valuesString)
if values.isEmpty {
Expand Down Expand Up @@ -654,7 +654,7 @@ open class SVGParser {
} else {
break
}
_ = scanner.scanString(",", into: nil)
_ = scanner.scannedString(",")
}

return collectedValues
Expand Down Expand Up @@ -704,7 +704,13 @@ open class SVGParser {
cleanedHexString = "\(x[0])\(x[0])\(x[1])\(x[1])\(x[2])\(x[2])"
}
var rgbValue: UInt32 = 0
Scanner(string: cleanedHexString).scanHexInt32(&rgbValue)
if #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) {
if let scannedInt = Scanner(string: cleanedHexString).scanUInt64(representation: .hexadecimal) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can match two conditions into one

if #available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *), let scannedInt = Scanner(string: cleanedHexString).scanUInt64(representation: .hexadecimal)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

rgbValue = UInt32(scannedInt)
}
} else {
Scanner(string: cleanedHexString).scanHexInt32(&rgbValue)
}

let red = CGFloat((rgbValue >> 16) & 0xff)
let green = CGFloat((rgbValue >> 08) & 0xff)
Expand Down Expand Up @@ -994,11 +1000,10 @@ open class SVGParser {

let scanner = Scanner(string: pointsString)
while !scanner.isAtEnd {
var resultPoint: Double = 0
if scanner.scanDouble(&resultPoint) {
if let resultPoint = scanner.scannedDouble() {
resultPoints.append(resultPoint)
}
_ = scanner.scanCharacters(from: [","], into: nil)
_ = scanner.scannedString(",")
}

if resultPoints.count % 2 == 1 {
Expand Down Expand Up @@ -2196,6 +2201,16 @@ fileprivate extension Scanner {
return scanUpTo(substring, into: &string) ? string as String? : nil
}
}

/// A version of `scanString(_:)`, available for an earlier OS.
func scannedString(_ searchString: String) -> String? {
if #available(OSX 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) {
return scanString(searchString)
} else {
var string: NSString?
return scanString(searchString, into: &string) ? string as String? : nil
}
}
}

fileprivate extension CharacterSet {
Expand Down