質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
iOS

iOSとは、Apple製のスマートフォンであるiPhoneやタブレット端末のiPadに搭載しているオペレーションシステム(OS)です。その他にもiPod touch・Apple TVにも搭載されています。

Xcode

Xcodeはソフトウェア開発のための、Appleの統合開発環境です。Mac OSXに付随するかたちで配布されています。

Swift

Swiftは、アップルのiOSおよびOS Xのためのプログラミング言語で、Objective-CやObjective-C++と共存することが意図されています

iPhone

iPhoneとは、アップル社が開発・販売しているスマートフォンです。 同社のデジタルオーディオプレーヤーiPodの機能、電話機能、インターネットやメールなどのWeb通信機能の3つをドッキングした機器です。

Q&A

解決済

2回答

2596閲覧

SwiftでDelegate設定時に"Class "ViewController" has no initializers"のエラーが出ます

ababab

総合スコア47

iOS

iOSとは、Apple製のスマートフォンであるiPhoneやタブレット端末のiPadに搭載しているオペレーションシステム(OS)です。その他にもiPod touch・Apple TVにも搭載されています。

Xcode

Xcodeはソフトウェア開発のための、Appleの統合開発環境です。Mac OSXに付随するかたちで配布されています。

Swift

Swiftは、アップルのiOSおよびOS Xのためのプログラミング言語で、Objective-CやObjective-C++と共存することが意図されています

iPhone

iPhoneとは、アップル社が開発・販売しているスマートフォンです。 同社のデジタルオーディオプレーヤーiPodの機能、電話機能、インターネットやメールなどのWeb通信機能の3つをドッキングした機器です。

0グッド

0クリップ

投稿2016/09/26 03:07

SwiftでDelegate設定時に「Class "ViewController" has no initializers"のエラーが出てしまいます。
現在実装しているのはGoogle Mapによる任意の場所の地図表示と現在地の地図表示です。

現在地の地図表示を実装する際にCLLocationManagerDelegateのDelegateを設定したのですが、その際にこのエラーが出ました。
この実装に必要なCoreLocation.frameworkは追加・importしてあります。

どのようにすれば解決するでしょうか?
よろしくお願いいたします。

コードはこちらになります(実装途中です)

swift

1import UIKit 2import CoreLocation 3 4import GoogleMaps 5 6// ここでエラー 7class ViewController: UIViewController, CLLocationManagerDelegate { 8 9 // 現在地の位置情報の取得にはCLLocationManagerを使用 10 var myLocationManager: CLLocationManager! 11 // 取得した緯度を保持するインスタンス 12 var latitude: CLLocationDegrees! 13 // 取得した経度を保持するインスタンス 14 var longitude: CLLocationDegrees! 15 16 var lonLabel: UILabel 17 var latLabel: UILabel 18 19 override func viewDidLoad() { 20 super.viewDidLoad() 21 // Do any additional setup after loading the view, typically from a nib. 22 23 let camera = GMSCameraPosition.camera(withLatitude: -33.86,longitude: 151.20, zoom: 6) 24 let mapView = GMSMapView.map(withFrame: CGRect(x:0, y:50, width:320, height:220), camera: camera) 25 self.view.addSubview(mapView); 26 27 let marker = GMSMarker() 28 marker.position = CLLocationCoordinate2DMake(-33.86, 151.20) 29 marker.title = "Sydney" 30 marker.snippet = "Australia" 31 marker.map = mapView 32 33 let nowcamera = GMSCameraPosition.camera(withLatitude: longitude,longitude: latitude, zoom: 6) 34 // let rect = CGRect(x: 100, y:50, width: 100, height: 100) 35 let nowmapView = GMSMapView.map(withFrame: CGRect(x:0, y:350, width:320, height:220), camera: nowcamera) 36 // mapView.isMyLocationEnabled = true 37 self.view.addSubview(nowmapView); 38 39 let nowmarker = GMSMarker() 40 nowmarker.position = CLLocationCoordinate2DMake(-33.86, 151.20) 41 nowmarker.title = "current location" 42 nowmarker.snippet = "now" 43 nowmarker.map = mapView 44 45 // 現在地を取得します 46 myLocationManager = CLLocationManager() 47 myLocationManager.delegate = self 48 myLocationManager.desiredAccuracy = kCLLocationAccuracyBest 49 myLocationManager.distanceFilter = 100 50 myLocationManager.startUpdatingLocation() 51 52 } 53 54 55 func getnowlocation() { 56 //現在地取得 57 myLocationManager.startUpdatingLocation() 58 } 59 60 private func locationManager(manager: CLLocationManager!,didUpdateLocations locations: [AnyObject]!){ 61 print("緯度:\(manager.location?.coordinate.latitude)") 62 print("経度:\(manager.location?.coordinate.longitude)") 63 } 64 65 /** 位置情報取得失敗時 */ 66 func locationManager(manager: CLLocationManager!, didFailWithError error: Error!) { 67 NSLog("Error") 68 } 69 70 override func didReceiveMemoryWarning() { 71 super.didReceiveMemoryWarning() 72 // Dispose of any resources that can be recreated. 73 } 74 75 76} 77 78

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答2

0

swift

1var lonLabel: UILabel 2var latLabel: UILabel

が非オプショナル型で定義されているのに初期化されてないからです。
lonLabelやlatLabelを後でどこかで設定するつもりなら!や?をつけてオプショナル型(初期値nil)にすればいいですし、そもそも使ってないなら削除すればいいです。

投稿2016/09/26 03:52

TakeOne

総合スコア6299

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

0

ベストアンサー

試せてませんが以下のように変更してもエラーがでますか?

swift

1var lonLabel: UILabel! 2var latLabel: UILabel!

投稿2016/09/26 03:35

_Kentarou

総合スコア8490

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問