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

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

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

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

Q&A

解決済

1回答

1142閲覧

Thread 1: Exception: "[<UIViewController 0x7fe17ac0bb90> setValue:forUndefinedKey:]の直し方

katuobot

総合スコア6

Swift

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

0グッド

0クリップ

投稿2020/06/09 11:42

開発環境
macOs catalina
xcode11.5

appdelegate.swiftに出るエラーが直せないです。

swift

1 2import UIKit 3import MapKit 4 5class MapViewController: UIViewController { 6 7 @IBOutlet weak var mapView: MKMapView! 8 9 //座標の配列 10 let coordinatesArray = [ 11 ["name":"東京駅", "lat":35.68124, "lon": 139.76672], 12 ["name":"皇居外苑", "lat":35.68026, "lon": 139.75801], 13 ["name":"国立劇場", "lat":35.6818, "lon": 139.74326], 14 ["name":"九段下駅", "lat":35.69555, "lon": 139.75074] 15 ] 16 17 override func viewDidLoad() { 18 super.viewDidLoad() 19 self.mapView.delegate = self 20 makeMap() 21 } 22 23 func makeMap(){ 24 //マップの表示域を設定 25 let coordinate = CLLocationCoordinate2DMake(coordinatesArray[0]["lat"] as! CLLocationDegrees, coordinatesArray[0]["lon"] as! CLLocationDegrees) 26 let span = MKCoordinateSpan(latitudeDelta: 0.05, longitudeDelta: 0.05) 27 let region = MKCoordinateRegion(center: coordinate, span: span) 28 self.mapView.setRegion(region, animated: true) 29 30 31 var routeCoordinates: [CLLocationCoordinate2D] = [] 32 for i in 0..<coordinatesArray.count { 33 let annotation = MKPointAnnotation() 34 let annotationCoordinate = CLLocationCoordinate2DMake(coordinatesArray[i]["lat"] as! CLLocationDegrees, coordinatesArray[i]["lon"] as! CLLocationDegrees) 35 annotation.title = coordinatesArray[i]["name"] as? String //ピンの吹き出しに名前が出るように 36 annotation.coordinate = annotationCoordinate 37 routeCoordinates.append(annotationCoordinate) 38 self.mapView.addAnnotation(annotation) 39 } 40 var myRoute: MKRoute! 41 let directionsRequest = MKDirections.Request() 42 var placemarks = [MKMapItem]() 43 //routeCoordinatesの配列からMKMapItemの配列にに変換 44 for item in routeCoordinates{ 45 let placemark = MKPlacemark(coordinate: item, addressDictionary: nil) 46 placemarks.append(MKMapItem(placemark: placemark)) 47 } 48 directionsRequest.transportType = .walking //移動手段は徒歩 49 for (k, item) in placemarks.enumerated(){ 50 if k < (placemarks.count - 1){ 51 directionsRequest.source = item //スタート地点 52 directionsRequest.destination = placemarks[k + 1] //目標地点 53 let direction = MKDirections(request: directionsRequest) 54 direction.calculate(completionHandler: {(response, error) in 55 if error == nil { 56 myRoute = response?.routes[0] 57 self.mapView.addOverlay(myRoute.polyline, level: .aboveRoads) //mapViewに絵画 58 } 59 }) 60 } 61 } 62 } 63} 64 65extension MapViewController:MKMapViewDelegate { 66 67 func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? { 68 if annotation is MKUserLocation { 69 return nil 70 } 71 let reuseId = "pin" 72 var pinView = mapView.dequeueReusableAnnotationView(withIdentifier: reuseId) 73 if pinView == nil { 74 pinView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: reuseId) 75 pinView?.canShowCallout = true //吹き出しで情報を表示出来るように 76 }else{ 77 pinView?.annotation = annotation 78 } 79 return pinView 80 } 81 82 //ピンを繋げている線の幅や色を調整 83 func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer { 84 let route: MKPolyline = overlay as! MKPolyline 85 let routeRenderer = MKPolylineRenderer(polyline: route) 86 routeRenderer.strokeColor = UIColor(red:1.00, green:0.35, blue:0.30, alpha:1.0) 87 routeRenderer.lineWidth = 3.0 88 return routeRenderer 89 } 90 91} 92

appdelegate.swiftのエラー

Thread 1: Exception: "[<UIViewController 0x7fe17ac0bb90> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key mapView."

デバッグエリアのエラー

2020-06-09 20:32:20.840216+0900 swiftmapp[1468:48890] [Storyboard] Unknown class _TtC9swiftmapp14ViewController in Interface Builder file. 2020-06-09 20:32:21.180363+0900 swiftmapp[1468:48890] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIViewController 0x7fe17ac0bb90> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key mapView.' *** First throw call stack: ( 0 CoreFoundation 0x00007fff23e3cf0e __exceptionPreprocess + 350 1 libobjc.A.dylib 0x00007fff50ba89b2 objc_exception_throw + 48 2 CoreFoundation 0x00007fff23e3cad9 -[NSException raise] + 9 3 Foundation 0x00007fff258e1bd6 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 325 4 UIKitCore 0x00007fff485d8412 -[UIViewController setValue:forKey:] + 87 5 UIKitCore 0x00007fff488e572f -[UIRuntimeOutletConnection connect] + 109 6 CoreFoundation 0x00007fff23e29222 -[NSArray makeObjectsPerformSelector:] + 242 7 UIKitCore 0x00007fff488e2918 -[UINib instantiateWithOwner:options:] + 2192 8 UIKitCore 0x00007fff485df81a -[UIViewController _loadViewFromNibNamed:bundle:] + 379 9 UIKitCore 0x00007fff485e0351 -[UIViewController loadView] + 177 10 UIKitCore 0x00007fff485e0650 -[UIViewController loadViewIfRequired] + 172 11 UIKitCore 0x00007fff485e0dfd -[UIViewController view] + 27 12 UIKitCore 0x00007fff48cc435d -[UIWindow addRootViewControllerViewIfPossible] + 326 13 UIKitCore 0x00007fff48cc3986 -[UIWindow _updateLayerOrderingAndSetLayerHidden:actionBlock:] + 219 14 UIKitCore 0x00007fff48cc4a11 -[UIWindow _setHidden:forced:] + 362 15 UIKitCore 0x00007fff48cd7e4d -[UIWindow _mainQueue_makeKeyAndVisible] + 42 16 UIKitCore 0x00007fff48ef9d63 -[UIWindowScene _makeKeyAndVisibleIfNeeded] + 202 17 UIKitCore 0x00007fff481e7d60 +[UIScene _sceneForFBSScene:create:withSession:connectionOptions:] + 1405 18 UIKitCore 0x00007fff48c87d2d -[UIApplication _connectUISceneFromFBSScene:transitionContext:] + 1019 19 UIKitCore 0x00007fff48c88064 -[UIApplication workspace:didCreateScene:withTransitionContext:completion:] + 291 20 UIKitCore 0x00007fff487da8dc -[UIApplicationSceneClientAgent scene:didInitializeWithEvent:completion:] + 361 21 FrontBoardServices 0x00007fff36cacd2e -[FBSSceneImpl _callOutQueue_agent_didCreateWithTransitionContext:completion:] + 419 22 FrontBoardServices 0x00007fff36cd2dc1 __86-[FBSWorkspaceScenesClient sceneID:createWithParameters:transitionContext:completion:]_block_invoke.154 + 102 23 FrontBoardServices 0x00007fff36cb7757 -[FBSWorkspace _calloutQueue_executeCalloutFromSource:withBlock:] + 220 24 FrontBoardServices 0x00007fff36cd2a52 __86-[FBSWorkspaceScenesClient sceneID:createWithParameters:transitionContext:completion:]_block_invoke + 355 25 libdispatch.dylib 0x0000000105cd1e8e _dispatch_client_callout + 8 26 libdispatch.dylib 0x0000000105cd4da2 _dispatch_block_invoke_direct + 300 27 FrontBoardServices 0x00007fff36cf86e9 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 30 28 FrontBoardServices 0x00007fff36cf83d7 -[FBSSerialQueue _queue_performNextIfPossible] + 441 29 FrontBoardServices 0x00007fff36cf88e6 -[FBSSerialQueue _performNextFromRunLoopSource] + 22 30 CoreFoundation 0x00007fff23da0d31 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17 31 CoreFoundation 0x00007fff23da0c5c __CFRunLoopDoSource0 + 76 32 CoreFoundation 0x00007fff23da048c __CFRunLoopDoSources0 + 268 33 CoreFoundation 0x00007fff23d9b02e __CFRunLoopRun + 974 34 CoreFoundation 0x00007fff23d9a944 CFRunLoopRunSpecific + 404 35 GraphicsServices 0x00007fff38ba6c1a GSEventRunModal + 139 36 UIKitCore 0x00007fff48c8b9ec UIApplicationMain + 1605 37 swiftmapp 0x0000000105a5451b main + 75 38 libdyld.dylib 0x00007fff51a231fd start + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException (lldb) ```

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

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

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

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

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

guest

回答1

0

ベストアンサー

Storyboard の ViewController のクラス名を MapViewController にしましょう。
イメージ説明

投稿2020/06/09 13:15

hoshi-takanori

総合スコア7895

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

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

katuobot

2020/06/10 09:04

できました!ありがとうございました!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

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

ただいまの回答率
85.48%

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

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

質問する

関連した質問