При использовании предварительного просмотра Xcode в представлении UIKIT отображается следующая ошибка:
';' statements are not allowed
----------------------------------------
CompileDylibError: Failed to build ViewController.swift
Compiling failed: ';' statements are not allowed
/Users/alphabo/Library/Developer/Xcode/DerivedData/RESThub-cesavxofrobmqdgtjbapqzddtkca/Build/Intermediates.noindex/Previews/RESThub/Intermediates.noindex/RESThub.build/Debug-iphonesimulator/RESThub.build/Objects-normal/x86_64/ViewController.2.preview-thunk.swift:76:18: error: ';' statements are not allowed
#sourceLocation();
^
/Users/alphabo/Library/Developer/Xcode/DerivedData/RESThub-cesavxofrobmqdgtjbapqzddtkca/Build/Intermediates.noindex/Previews/RESThub/Intermediates.noindex/RESThub.build/Debug-iphonesimulator/RESThub.build/Objects-normal/x86_64/ViewController.2.preview-thunk.swift:84:18: error: ';' statements are not allowed
#sourceLocation();
^
Проект Xcode компилируется без ошибок или предупреждений, но предварительный просмотр не работает. Ниже приведен исходный код ViewController:
//
// ViewController.swift
// RESThub
//
// Created by Harrison on 7/25/19.
// Copyright © 2019 Harrison. All rights reserved.
//
import UIKit
final class RestViewController: UIViewController {
// MARK: Outlets
@IBOutlet weak var feedTableView: UITableView!
// MARK: Variables
override func viewDidLoad() {
super.viewDidLoad()
// TODO: GET a list of gists
}
@IBAction func createNewGist(_ sender: UIButton) {
// TODO: POST a new gist
}
// MARK: Utilities
func showResultAlert(title: String, message: String) {
let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: "Dismiss", style: .default))
self.present(alertController, animated: true, completion: nil)
}
}
// MARK: UITableView Delegate & DataSource
extension RestViewController: UITableViewDelegate, UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1;
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "feedCellID", for: indexPath)
return cell;
}
func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
let starAction = UIContextualAction(style: .normal, title: "Star") { (action, view, completion) in
// TODO: PUT a gist star
completion(true)
}
let unstarAction = UIContextualAction(style: .normal, title: "Unstar") { (action, view, completion) in
// TODO: DELETE a gist star
completion(true)
}
starAction.backgroundColor = .blue
unstarAction.backgroundColor = .darkGray
let actionConfig = UISwipeActionsConfiguration(actions: [unstarAction, starAction])
return actionConfig
}
}
#if DEBUG
import SwiftUI
extension RestViewController: UIViewControllerRepresentable {
func makeUIViewController(context: Context) -> RestViewController {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
guard let viewController = storyboard.instantiateViewController(identifier: "ViewController") as? RestViewController else {fatalError("Cannot load from storyboard")}
return viewController
}
func updateUIViewController(_ uiViewController: RestViewController, context: Context) {
}
}
#endif
// MontactListControllerPreviews.swift
#if DEBUG
import SwiftUI
struct TermsViewControllerPreviews: PreviewProvider {
static var previews: some View {
NavigationView {
RestViewController()
.navigationBarTitle("Contacts")
}
}
}
#endif
Проект на GitHub