Skip to content

Commit

Permalink
Add any keywords to existential types
Browse files Browse the repository at this point in the history
In Swift 6, this will be required. It is compatible with Swift 5.7.
  • Loading branch information
Eitot committed Jun 23, 2024
1 parent 5f1d600 commit 600d54b
Show file tree
Hide file tree
Showing 17 changed files with 51 additions and 51 deletions.
2 changes: 1 addition & 1 deletion Vienna/Sources/Application/DispatchTimer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import os.log
@objc(VNADispatchTimer)
class DispatchTimer: NSObject {

private var dispatchSource: DispatchSourceTimer
private var dispatchSource: any DispatchSourceTimer

private(set) var interval: TimeInterval

Expand Down
2 changes: 1 addition & 1 deletion Vienna/Sources/Criteria/Criteria+NSPredicate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ extension CriteriaTree: PredicateConvertible {
}

for subPredicate in subPredicates {
let criteriaElement: CriteriaElement?
let criteriaElement: (any CriteriaElement)?

if let subCompound = subPredicate as? NSCompoundPredicate {
// Look ahead to detect "not contains" predicate
Expand Down
18 changes: 9 additions & 9 deletions Vienna/Sources/Criteria/Criteria+XML.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ import Foundation
class CriteriaXmlConverter {

@objc
static func toXml(_ criteriaElement: CriteriaElement) -> XMLElement {
guard let criteriaElement = criteriaElement as? Traversable else {
static func toXml(_ criteriaElement: any CriteriaElement) -> XMLElement {
guard let criteriaElement = criteriaElement as? any Traversable else {
fatalError("All CriteriaElement subtypes must be Traversable!")
}
return toXml(criteriaElement)
}

static func toXml(_ criteriaElement: Traversable) -> XMLElement {
static func toXml(_ criteriaElement: any Traversable) -> XMLElement {
return criteriaElement.traverse { element, subresult in
let criteriaTreeXml = XMLElement(name: CriteriaTree.groupTag)
criteriaTreeXml.setAttributesWith([CriteriaTree.conditionAttribute: "\(element.condition)"])
Expand All @@ -52,14 +52,14 @@ class CriteriaXmlConverter {
}

@objc
static func from(xml: XMLElement?) -> CriteriaElement? {
static func from(xml: XMLElement?) -> (any CriteriaElement)? {
guard let (subtree, condition) = subtreeAndConditionFrom(xml: xml) else {
return nil
}
return CriteriaTree(subtree: subtree, condition: condition)
}

static func subtreeAndConditionFrom(xml: XMLElement?) -> (subtree: [Traversable], condition: CriteriaCondition)? {
static func subtreeAndConditionFrom(xml: XMLElement?) -> (subtree: [any Traversable], condition: CriteriaCondition)? {
guard let xml = xml else {
NSLog("CriteriaTree cannot be initialized from nil xml")
return nil
Expand All @@ -69,14 +69,14 @@ class CriteriaXmlConverter {
// assumes that we're matching ALL conditions.
let conditionString = xml.attribute(forName: CriteriaTree.conditionAttribute)?.stringValue ?? ""

var subtree: [Traversable] = []
var subtree: [any Traversable] = []
for child in xml.children ?? [] {
guard let child = child as? XMLElement,
child.name == CriteriaTree.groupTag || child.name == CriteriaTree.criteriaTag else {
NSLog("Invalid node \(child) in criteria xml discovered.")
return nil
}
let subCriteriaElement: CriteriaElement
let subCriteriaElement: any CriteriaElement
if child.name == CriteriaTree.groupTag {
guard let subCriteriaTree = CriteriaTree(xml: child) else {
NSLog("CriteriaTree cannot be initialized from \(child)")
Expand All @@ -90,7 +90,7 @@ class CriteriaXmlConverter {
}
subCriteriaElement = subCriterion
}
guard let subtreeElement = subCriteriaElement as? Traversable else {
guard let subtreeElement = subCriteriaElement as? (any Traversable) else {
fatalError("All CriteriaElement subtypes must be Traversable!")
}
subtree.append(subtreeElement)
Expand Down Expand Up @@ -127,7 +127,7 @@ extension CriteriaTree {

@objc
convenience init?(string: String) {
var xmlError: Error?
var xmlError: (any Error)?
var criteriaTreeXml: XMLDocument?
do {
criteriaTreeXml = try XMLDocument(xmlString: string)
Expand Down
8 changes: 4 additions & 4 deletions Vienna/Sources/Criteria/Criteria.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,24 +98,24 @@ protocol Traversable: CriteriaElement {
@objc
class CriteriaTree: NSObject, Traversable {
// Workaround while this variable is needed for objc (Traversable cannot be exposed)
@objc var criteriaTree: [CriteriaElement] {
@objc var criteriaTree: [any CriteriaElement] {
get {
traversableTree
}
set {
self.traversableTree = newValue as? [Traversable] ?? []
self.traversableTree = newValue as? [any Traversable] ?? []
}
}

var condition: CriteriaCondition

var traversableTree: [Traversable]
var traversableTree: [any Traversable]

override convenience init() {
self.init(subtree: [], condition: .all)
}

init(subtree: [Traversable], condition: CriteriaCondition) {
init(subtree: [any Traversable], condition: CriteriaCondition) {
traversableTree = subtree
self.condition = condition
}
Expand Down
2 changes: 1 addition & 1 deletion Vienna/Sources/Main window/ArticleContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Cocoa
@objc
protocol ArticleContentView {

var listView: ArticleViewDelegate? { get set }
var listView: (any ArticleViewDelegate)? { get set }
var articles: [Article] { get set }

@objc(keyDown:)
Expand Down
4 changes: 2 additions & 2 deletions Vienna/Sources/Main window/Browser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ protocol Browser {
/// A tabbed browser always has one tab that is selected. It is called the active tab.
/// In case the primary tab is selected, the return value is nil
/// (because it does not necessarily implement the Tab protocol)
var activeTab: Tab? { get }
var activeTab: (any Tab)? { get }

/// Add a new tab to the open tabs of the browser
///
Expand All @@ -46,7 +46,7 @@ protocol Browser {
/// - load: whether the page to which the URL points is supposed to be loaded immediately
/// (otherwise it is opened when opening the tab)
/// - Returns: the new tab
func createNewTab(_ url: URL?, inBackground: Bool, load: Bool) -> Tab
func createNewTab(_ url: URL?, inBackground: Bool, load: Bool) -> any Tab

/// Saves all tabs persistently.
/// Next time when instanciating the browser, these tabs will be re-instanciated as well.
Expand Down
2 changes: 1 addition & 1 deletion Vienna/Sources/Main window/BrowserTab+RSSSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ extension BrowserTab: RSSSource {
}
}

var rssSubscriber: RSSSubscriber? {
var rssSubscriber: (any RSSSubscriber)? {
get {
self.rssDelegate
}
Expand Down
6 changes: 3 additions & 3 deletions Vienna/Sources/Main window/BrowserTab.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class BrowserTab: NSViewController {
var navigationEndHandler: [(_ success: Bool) -> Void] = []

/// backing storage only, access via rssSubscriber property
weak var rssDelegate: RSSSubscriber?
weak var rssDelegate: (any RSSSubscriber)?
/// backing storage only, access via rssUrl property
var rssFeedUrls: [URL] = []

Expand Down Expand Up @@ -353,12 +353,12 @@ extension BrowserTab: WKNavigationDelegate {
handleNavigationStart()
}

func webView(_ webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation?, withError error: Error) {
func webView(_ webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation?, withError error: any Error) {
// TODO: provisional navigation fail seems to translate to error in resolving URL or similar. Treat different from normal navigation fail
handleNavigationEnd(success: false)
}

func webView(_ webView: WKWebView, didFail navigation: WKNavigation?, withError error: Error) {
func webView(_ webView: WKWebView, didFail navigation: WKNavigation?, withError error: any Error) {
// TODO: show failure to load as page or symbol
handleNavigationEnd(success: false)
}
Expand Down
2 changes: 1 addition & 1 deletion Vienna/Sources/Main window/ButtonToolbarItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class ButtonToolbarItem: NSToolbarItem {
}

switch NSApp.target(forAction: action, to: target, from: self) {
case let validator as NSToolbarItemValidation:
case let validator as any NSToolbarItemValidation:
isEnabled = validator.validateToolbarItem(self)
default:
isEnabled = false
Expand Down
8 changes: 4 additions & 4 deletions Vienna/Sources/Main window/CustomWKWebView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ class CustomWKWebView: WKWebView {
// store weakly here because contentController retains listener
weak var contextMenuListener: CustomWKWebViewContextMenuListener?

weak var contextMenuProvider: CustomWKUIDelegate? {
weak var contextMenuProvider: (any CustomWKUIDelegate)? {
didSet {
self.uiDelegate = contextMenuProvider
}
}

@objc weak var hoverUiDelegate: CustomWKHoverUIDelegate? {
@objc weak var hoverUiDelegate: (any CustomWKHoverUIDelegate)? {
didSet {
resetHoverUiListener()
}
Expand Down Expand Up @@ -393,9 +393,9 @@ extension CustomWKWebView {

class CustomWKWebViewHoverListener: NSObject, WKScriptMessageHandler {

weak var hoverDelegate: CustomWKHoverUIDelegate?
weak var hoverDelegate: (any CustomWKHoverUIDelegate)?

init(hoverDelegate: CustomWKHoverUIDelegate) {
init(hoverDelegate: any CustomWKHoverUIDelegate) {
self.hoverDelegate = hoverDelegate
}

Expand Down
10 changes: 5 additions & 5 deletions Vienna/Sources/Main window/MainWindowController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ final class MainWindowController: NSWindowController {
@objc private(set) var toolbarSearchField: NSSearchField?
@IBOutlet private(set) weak var placeholderDetailView: NSView!

@objc private(set) lazy var browser: (Browser & NSViewController) = {
var controller = TabbedBrowserViewController() as (Browser & NSViewController)
@objc private(set) lazy var browser: (any Browser & NSViewController) = {
var controller = TabbedBrowserViewController() as (any Browser & NSViewController)
return controller
}()

Expand All @@ -48,7 +48,7 @@ final class MainWindowController: NSWindowController {
// cf. https://stackoverflow.com/q/16587058
splitView.autosaveName = "VNASplitView"

(self.browser as? RSSSource)?.rssSubscriber = self
(self.browser as? any RSSSource)?.rssSubscriber = self

statusBarState(disclosed: Preferences.standard.showStatusBar, animate: false)

Expand Down Expand Up @@ -177,7 +177,7 @@ final class MainWindowController: NSWindowController {

var shareableItemsSubject = String()

private var shareableItems: [NSPasteboardWriting] {
private var shareableItems: [any NSPasteboardWriting] {
var items = [URL]()
if let activeTab = browser.activeTab, let url = activeTab.tabUrl {
items.append(url)
Expand Down Expand Up @@ -518,7 +518,7 @@ extension MainWindowController: NSSharingServicePickerDelegate {
func sharingServicePicker(
_ sharingServicePicker: NSSharingServicePicker,
delegateFor sharingService: NSSharingService
) -> NSSharingServiceDelegate? {
) -> (any NSSharingServiceDelegate)? {
return self
}

Expand Down
2 changes: 1 addition & 1 deletion Vienna/Sources/Main window/RSSSubscriber.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,5 @@ extension RSSSubscriber {
}

protocol RSSSource: AnyObject {
var rssSubscriber: RSSSubscriber? { get set }
var rssSubscriber: (any RSSSubscriber)? { get set }
}
22 changes: 11 additions & 11 deletions Vienna/Sources/Main window/TabbedBrowserViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,18 @@ class TabbedBrowserViewController: NSViewController, RSSSource {

var restoredTabs = false

var activeTab: Tab? {
tabView?.selectedTabViewItem?.viewController as? Tab
var activeTab: (any Tab)? {
tabView?.selectedTabViewItem?.viewController as? any Tab
}

var browserTabCount: Int {
tabView?.numberOfTabViewItems ?? 0
}

weak var rssSubscriber: RSSSubscriber? {
weak var rssSubscriber: (any RSSSubscriber)? {
didSet {
for source in tabView?.tabViewItems ?? [] {
(source as? RSSSource)?.rssSubscriber = self.rssSubscriber
(source as? any RSSSource)?.rssSubscriber = self.rssSubscriber
}
}
}
Expand Down Expand Up @@ -152,21 +152,21 @@ class TabbedBrowserViewController: NSViewController, RSSSource {
}

extension TabbedBrowserViewController: Browser {
func createNewTab(_ url: URL?, inBackground: Bool, load: Bool) -> Tab {
func createNewTab(_ url: URL?, inBackground: Bool, load: Bool) -> any Tab {
createNewTab(url, inBackground: inBackground, load: load, insertAt: nil)
}

func createNewTab(_ request: URLRequest, config: WKWebViewConfiguration, inBackground: Bool, insertAt index: Int? = nil) -> Tab {
func createNewTab(_ request: URLRequest, config: WKWebViewConfiguration, inBackground: Bool, insertAt index: Int? = nil) -> any Tab {
let newTab = BrowserTab(request, config: config)
return initNewTab(newTab, request.url, false, inBackground, insertAt: index)
}

func createNewTab(_ url: URL? = nil, inBackground: Bool = false, load: Bool = false, insertAt index: Int? = nil) -> Tab {
func createNewTab(_ url: URL? = nil, inBackground: Bool = false, load: Bool = false, insertAt index: Int? = nil) -> any Tab {
let newTab = BrowserTab()
return initNewTab(newTab, url, load, inBackground, insertAt: index)
}

private func initNewTab(_ newTab: BrowserTab, _ url: URL?, _ load: Bool, _ inBackground: Bool, insertAt index: Int? = nil) -> Tab {
private func initNewTab(_ newTab: BrowserTab, _ url: URL?, _ load: Bool, _ inBackground: Bool, insertAt index: Int? = nil) -> any Tab {
newTab.rssSubscriber = self.rssSubscriber

let newTabViewItem = TitleChangingTabViewItem(viewController: newTab)
Expand Down Expand Up @@ -258,7 +258,7 @@ extension TabbedBrowserViewController: MMTabBarViewDelegate {
}

func tabView(_ aTabView: NSTabView, willClose tabViewItem: NSTabViewItem) {
guard let tab = tabViewItem.viewController as? Tab else {
guard let tab = tabViewItem.viewController as? any Tab else {
return
}
tab.closeTab()
Expand Down Expand Up @@ -288,7 +288,7 @@ extension TabbedBrowserViewController: MMTabBarViewDelegate {
tabViewItem != primaryTab
}

func tabView(_ aTabView: NSTabView, validateDrop sender: NSDraggingInfo, proposedItem tabViewItem: NSTabViewItem, proposedIndex: UInt, in tabBarView: MMTabBarView) -> NSDragOperation {
func tabView(_ aTabView: NSTabView, validateDrop sender: any NSDraggingInfo, proposedItem tabViewItem: NSTabViewItem, proposedIndex: UInt, in tabBarView: MMTabBarView) -> NSDragOperation {
proposedIndex != 0 ? [.every] : []
}

Expand Down Expand Up @@ -321,7 +321,7 @@ extension TabbedBrowserViewController: MMTabBarViewDelegate {
extension TabbedBrowserViewController: CustomWKUIDelegate {
// TODO: implement functionality for alerts and maybe peek actions

private static var contextMenuCustomizer: BrowserContextMenuDelegate = WebKitContextMenuCustomizer()
private static var contextMenuCustomizer: any BrowserContextMenuDelegate = WebKitContextMenuCustomizer()

func webView(_ webView: WKWebView, createWebViewWith configuration: WKWebViewConfiguration, for navigationAction: WKNavigationAction, windowFeatures: WKWindowFeatures) -> WKWebView? {
let newTab = self.createNewTab(navigationAction.request, config: configuration, inBackground: false, insertAt: getIndexAfterSelected())
Expand Down
4 changes: 2 additions & 2 deletions Vienna/Sources/Main window/WebKitArticleTab.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class WebKitArticleTab: BrowserTab, ArticleContentView {
}
}

var listView: ArticleViewDelegate?
var listView: (any ArticleViewDelegate)?

var articles: [Article] {
get {
Expand Down Expand Up @@ -119,7 +119,7 @@ class WebKitArticleTab: BrowserTab, ArticleContentView {
NotificationCenter.default.post(name: .articleViewEnded, object: self)
}

override func webView(_ webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: Error) {
override func webView(_ webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: any Error) {
super.webView(webView, didFailProvisionalNavigation: navigation, withError: error)
NotificationCenter.default.post(name: .articleViewEnded, object: self)
}
Expand Down
4 changes: 2 additions & 2 deletions Vienna/Sources/Main window/WebKitArticleView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import WebKit

class WebKitArticleView: CustomWKWebView, ArticleContentView, WKNavigationDelegate, CustomWKUIDelegate {

var listView: ArticleViewDelegate?
var listView: (any ArticleViewDelegate)?

var articles: [Article] = [] {
didSet {
Expand All @@ -43,7 +43,7 @@ class WebKitArticleView: CustomWKWebView, ArticleContentView, WKNavigationDelega

let converter = WebKitArticleConverter()

let contextMenuCustomizer: BrowserContextMenuDelegate = WebKitContextMenuCustomizer()
let contextMenuCustomizer: any BrowserContextMenuDelegate = WebKitContextMenuCustomizer()

@objc
init(frame: NSRect) {
Expand Down
4 changes: 2 additions & 2 deletions Vienna/Sources/Parsing/JSONFeed.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class JSONFeed: NSObject, Feed, Decodable {
var modifiedDate: Date?

// The `items` key is required (but the array may be empty).
var items: [FeedItem]
var items: [any FeedItem]

// MARK: Decodable

Expand All @@ -52,7 +52,7 @@ class JSONFeed: NSObject, Feed, Decodable {
case author
}

required init(from decoder: Decoder) throws {
required init(from decoder: any Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)

title = try container.decode(String.self, forKey: .title)
Expand Down
2 changes: 1 addition & 1 deletion Vienna/Sources/Parsing/JSONFeedItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class JSONFeedItem: NSObject, FeedItem, Decodable {
case attachments
}

required init(from decoder: Decoder) throws {
required init(from decoder: any Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)

guid = try container.decode(String.self, forKey: .id)
Expand Down

0 comments on commit 600d54b

Please sign in to comment.