前提・実現したいこと
お世話になっております。
現在、Wi-Fiに接続しているかどうかの判定できるアプリケーションを作成しています。
ボタンをタップしたときに判定し、Wi-Fiに接続されていない場合設定画面に遷移するよう促すアラートを表示するようにしたいと考えています。
継承の勉強も兼ねて、敢えて2つのファイルを作成していますが、「Multiple inheritance from classes 'UIViewController' and 'NetAlert'」とエラーが出てしまいます。
どの様に解決すればいいのか分からないため、ご教授よろしくお願いします。
発生している問題・エラーメッセージ
Multiple inheritance from classes 'UIViewController' and 'NetAlert'
該当のソースコード
Swift
1import UIKit 2 3class NetAlert { 4 func alert(){ 5 DispatchQueue.main.async { 6 7 let changePrivatySetting = "インターネットに接続できません。設定画面に移りますか?" 8 let message = NSLocalizedString(changePrivatySetting, comment: "インターネットに接続できません。設定画面に移りますか?") 9 let alertController = UIAlertController(title: "インターネットに接続できません", message: message, preferredStyle: .alert) 10 alertController.addAction(UIAlertAction(title: NSLocalizedString("キャンセル", comment: "Alert Cancel button"), style: .cancel, handler: nil)) 11 alertController.addAction(UIAlertAction(title: NSLocalizedString("設定", 12 comment: "Alert button to open Settings"), 13 style: .default, handler: { _ in 14 UIApplication.shared.open(URL(string: "App-Prefs:root")!, options: [:], completionHandler: nil) 15 })) 16 } 17 } 18} 19
Swift
1import UIKit 2import Reachability 3 4//以下に「Multiple inheritance from classes 'UIViewController' and 'NetAlert'」と出る 5class ViewController: UIViewController, NetAlert { 6 7 let reachability = Reachability()! 8 9 10 @IBAction func btn(_ sender: Any) { 11 let reachability = Reachability()! 12 13 14 reachability.whenReachable = { reachability in 15 if reachability.connection == .wifi { 16 print("Wi-Fiに繋がってるよ") 17 } 18 } 19 reachability.whenUnreachable = { _ in 20 if reachability.connection == .none { 21 print("電波無いよ") 22 NetAlert().alert() 23 } 24 25 } 26 do { 27 try reachability.startNotifier() 28 } catch { 29 print("Unable to start notifier") 30 } 31 } 32 33}
補足情報(FW/ツールのバージョンなど)
使用ツール:Xcode9.4 使用言語:Swift4

回答2件
あなたの回答
tips
プレビュー
下記のような回答は推奨されていません。
このような回答には修正を依頼しましょう。
また依頼した内容が修正された場合は、修正依頼を取り消すようにしましょう。
2018/06/15 06:34
2018/06/15 06:59
2018/06/15 07:14