Skip to content

Commit

Permalink
Merge pull request #736 from damienpontifex/deprecations
Browse files Browse the repository at this point in the history
OS version availability checks to resolve deprecation warnings
  • Loading branch information
ystrot authored Oct 19, 2020
2 parents faf3ab8 + d54af83 commit 2b406e5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
6 changes: 5 additions & 1 deletion Source/platform/iOS/MDisplayLink_iOS.swift
Original file line number Diff line number Diff line change
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
29 changes: 21 additions & 8 deletions Source/svg/SVGParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -549,14 +549,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 @@ -659,7 +659,7 @@ open class SVGParser {
} else {
break
}
_ = scanner.scanString(",", into: nil)
_ = scanner.scannedString(",")
}

return collectedValues
Expand Down Expand Up @@ -709,7 +709,11 @@ 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, *), let scannedInt = Scanner(string: cleanedHexString).scanUInt64(representation: .hexadecimal) {
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 @@ -999,11 +1003,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 @@ -2245,6 +2248,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

0 comments on commit 2b406e5

Please sign in to comment.