Skip to content

Commit

Permalink
Resolve implicitly_unwrapped_optional violations in SampleBrowser
Browse files Browse the repository at this point in the history
  • Loading branch information
tonell-m committed Jan 22, 2025
1 parent 6ecd083 commit cdbff29
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
8 changes: 4 additions & 4 deletions SampleBrowser/SampleBrowser/Engine/EngineProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import WebEngine

struct EngineProvider {
// We only have one session in the SampleBrowser
private(set) var session: EngineSession?
private(set) var session: EngineSession
let view: EngineView

init(engine: Engine = WKEngine.factory(),
sessionDependencies: EngineSessionDependencies? = nil) {
init?(engine: Engine = WKEngine.factory(),
sessionDependencies: EngineSessionDependencies? = nil) {
do {
session = try engine.createSession(dependencies: sessionDependencies)
} catch {
session = nil
return nil
}

view = engine.createView()
Expand Down
4 changes: 2 additions & 2 deletions SampleBrowser/SampleBrowser/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import WebEngine

class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
var engineProvider: EngineProvider = {
var engineProvider: EngineProvider? = {
let dependencies = EngineSessionDependencies(telemetryProxy: TelemetryHandler())
return EngineProvider(sessionDependencies: dependencies)
}()

func scene(_ scene: UIScene,
willConnectTo session: UISceneSession,
options connectionOptions: UIScene.ConnectionOptions) {
guard let windowScene = (scene as? UIWindowScene) else { return }
guard let windowScene = (scene as? UIWindowScene), let engineProvider else { return }
let windowUUID = UUID()
let baseViewController = RootViewController(engineProvider: engineProvider, windowUUID: windowUUID)
window = UIWindow(windowScene: windowScene)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class BrowserViewController: UIViewController,
FindInPageHelperDelegate {
weak var navigationDelegate: NavigationDelegate?
private lazy var progressView: UIProgressView = .build { _ in }
private var engineSession: EngineSession!
private var engineSession: EngineSession
private var engineView: EngineView
private let urlFormatter: URLFormatter

Expand Down Expand Up @@ -203,7 +203,7 @@ class BrowserViewController: UIViewController,
guard let url = linkURL else { return nil }

let previewProvider: UIContextMenuContentPreviewProvider = {
let previewEngineProvider = EngineProvider()
guard let previewEngineProvider = EngineProvider() else { return nil }
let previewVC = BrowserViewController(engineProvider: previewEngineProvider)
previewVC.engineSession.load(url: url.absoluteString)
return previewVC
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ protocol SuggestionViewControllerDelegate: AnyObject {

class SuggestionViewController: UIViewController, UITableViewDelegate {
private var tableView: UITableView
private var dataSource: SuggestionDataSource!
private var dataSource: SuggestionDataSource?
private weak var delegate: SuggestionViewControllerDelegate?

private var gradientLayer: CAGradientLayer?
Expand Down Expand Up @@ -87,14 +87,14 @@ class SuggestionViewController: UIViewController, UITableViewDelegate {

func updateUI(for suggestions: [String]) {
tableView.isHidden = suggestions.isEmpty
dataSource.suggestions = suggestions
dataSource?.suggestions = suggestions
tableView.reloadData()
}

// MARK: - UITableViewDelegate

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let term = dataSource.suggestions[indexPath.row]
guard let term = dataSource?.suggestions[indexPath.row] else { return }
delegate?.tapOnSuggestion(term: term)
}
}

0 comments on commit cdbff29

Please sign in to comment.