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

Xcode recommended changes for Swift 4.2 #83

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/WKZombie/HTMLPage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class HTMLPage : HTMLParser, Page {
public func findElements<T>(_ searchType: SearchType<T>) -> Result<[T]> {
let query = searchType.xPathQuery()
if let parsedObjects = searchWithXPathQuery(query) , parsedObjects.count > 0 {
return resultFromOptional(parsedObjects.flatMap { T(element: $0, XPathQuery: query) }, error: .notFound)
return resultFromOptional(parsedObjects.compactMap { T(element: $0, XPathQuery: query) }, error: .notFound)
}
return Result.error(.notFound)
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/WKZombie/Parser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,11 @@ public class HTMLParserElement : CustomStringConvertible {
}

public func childrenWithTagName<T: HTMLElement>(_ tagName: String) -> [T]? {
return element?.children(withTagName: tagName).flatMap { T(element: $0 as AnyObject) }
return element?.children(withTagName: tagName).compactMap { T(element: $0 as AnyObject) }
}

public func children<T: HTMLElement>() -> [T]? {
return element?.children.flatMap { T(element:$0 as AnyObject) }
return element?.children.compactMap { T(element:$0 as AnyObject) }
}

public func hasChildren() -> Bool {
Expand Down
4 changes: 2 additions & 2 deletions Sources/WKZombie/RenderOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ internal class RenderOperation : Operation {
func wait(_ condition: () -> Bool) {
let updateInterval : TimeInterval = 0.1
var loopUntil = Date(timeIntervalSinceNow: updateInterval)
while condition() == false && RunLoop.current.run(mode: RunLoopMode.defaultRunLoopMode, before: loopUntil) {
while condition() == false && RunLoop.current.run(mode: RunLoop.Mode.default, before: loopUntil) {
loopUntil = Date(timeIntervalSinceNow: updateInterval)
Logger.log(".", lineBreak: false)
}
Expand Down Expand Up @@ -149,7 +149,7 @@ internal class RenderOperation : Operation {
fileprivate func startTimeout() {
stopRunLoop = false
timeout = Timer(timeInterval: timeoutInSeconds, target: self, selector: #selector(RenderOperation.cancel), userInfo: nil, repeats: false)
RunLoop.current.add(timeout!, forMode: RunLoopMode.defaultRunLoopMode)
RunLoop.current.add(timeout!, forMode: RunLoop.Mode.default)
}

fileprivate func stopTimeout() {
Expand Down
2 changes: 1 addition & 1 deletion Sources/WKZombie/Renderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ extension Renderer {
let snapshot = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()

if let data = UIImagePNGRepresentation(snapshot!) {
if let data = snapshot!.pngData() {
return Snapshot(data: data, page: webView.url)
}
return nil
Expand Down