4つのtext filedに値を入れ計算した3つ答えを書き出すアプリを開発しています。
iPhoneのデモ画面を起動したところ以下のようなエラーが出てしまいました。
作成したコードにはエラー表示がされていませんでした。
以下のサイトを参考にエラーをなくそうとしたのですが...
どのようにすればエラーが解決するでしょうか?ご教授お願いいたします。
swift初心者:「this class is not key value coding-compliant for the key」の対処方法 - Qiita
2021-05-15 17:34:29.504344+0900 o2[3184:117685] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<o2.ViewController 0x7fa9f0706c90> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key b.'
*** First throw call stack:
(
0 CoreFoundation 0x00007fff20422fba __exceptionPreprocess + 242
1 libobjc.A.dylib 0x00007fff20193ff5 objc_exception_throw + 48
2 CoreFoundation 0x00007fff20422c5b -[NSException init] + 0
3 Foundation 0x00007fff207af46c -[NSObject(NSKeyValueCoding) setValue:forKey:] + 331
4 UIKitCore 0x00007fff23f7cac4 -[UIViewController setValue:forKey:] + 74
5 UIKitCore 0x00007fff242bbc0b -[UIRuntimeOutletConnection connect] + 109
6 CoreFoundation 0x00007fff2040c6e6 -[NSArray makeObjectsPerformSelector:] + 228
7 UIKitCore 0x00007fff242b7e70 -[UINib instantiateWithOwner:options:] + 2175
8 UIKitCore 0x00007fff23f84921 -[UIViewController loadView] + 668
9 UIKitCore 0x00007fff23f84cbc -[UIViewController loadViewIfRequired] + 172
10 UIKitCore 0x00007fff23f85436 -[UIViewController view] + 27
11 UIKitCore 0x00007fff246ffc73 -[UIWindow addRootViewControllerViewIfPossible] + 313
12 UIKitCore 0x00007fff246ff362 -[UIWindow _updateLayerOrderingAndSetLayerHidden:actionBlock:] + 219
13 UIKitCore 0x00007fff24700325 -[UIWindow _setHidden:forced:] + 362
14 UIKitCore 0x00007fff247133a6 -[UIWindow _mainQueue_makeKeyAndVisible] + 42
15 UIKitCore 0x00007fff24951c05 -[UIWindowScene _makeKeyAndVisibleIfNeeded] + 202
16 UIKitCore 0x00007fff23b0e80c +[UIScene _sceneForFBSScene:create:withSession:connectionOptions:] + 1671
17 UIKitCore 0x00007fff246c2df9 -[UIApplication _connectUISceneFromFBSScene:transitionContext:] + 1114
18 UIKitCore 0x00007fff246c3128 -[UIApplication workspace:didCreateScene:withTransitionContext:completion:] + 289
19 UIKitCore 0x00007fff241a4ab4 -[UIApplicationSceneClientAgent scene:didInitializeWithEvent:completion:] + 358
20 FrontBoardServices 0x00007fff25a1b40b -[FBSScene _callOutQueue_agent_didCreateWithTransitionContext:completion:] + 398
21 FrontBoardServices 0x00007fff25a43e55 __94-[FBSWorkspaceScenesClient createWithSceneID:groupID:parameters:transitionContext:completion:]_block_invoke.176 + 102
22 FrontBoardServices 0x00007fff25a28f12 -[FBSWorkspace _calloutQueue_executeCalloutFromSource:withBlock:] + 209
23 FrontBoardServices 0x00007fff25a43b28 __94-[FBSWorkspaceScenesClient createWithSceneID:groupID:parameters:transitionContext:completion:]_block_invoke + 352
24 libdispatch.dylib 0x0000000101e9174e _dispatch_client_callout + 8
25 libdispatch.dylib 0x0000000101e94656 _dispatch_block_invoke_direct + 295
26 FrontBoardServices 0x00007fff25a695d0 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 30
27 FrontBoardServices 0x00007fff25a692b6 -[FBSSerialQueue _targetQueue_performNextIfPossible] + 433
28 FrontBoardServices 0x00007fff25a6977b -[FBSSerialQueue _performNextFromRunLoopSource] + 22
29 CoreFoundation 0x00007fff20390ede __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
30 CoreFoundation 0x00007fff20390dd6 __CFRunLoopDoSource0 + 180
31 CoreFoundation 0x00007fff20390300 __CFRunLoopDoSources0 + 340
32 CoreFoundation 0x00007fff2038a9f7 __CFRunLoopRun + 875
33 CoreFoundation 0x00007fff2038a1a7 CFRunLoopRunSpecific + 567
34 GraphicsServices 0x00007fff2b874d85 GSEventRunModal + 139
35 UIKitCore 0x00007fff246c14df -[UIApplication _run] + 912
36 UIKitCore 0x00007fff246c639c UIApplicationMain + 101
37 libswiftUIKit.dylib 0x00007fff53fcbf42 $s5UIKit17UIApplicationMainys5Int32VAD_SpySpys4Int8VGGSgSSSgAJtF + 98
38 o2 0x0000000101c0a42a $sSo21UIApplicationDelegateP5UIKitE4mainyyFZ + 122
39 o2 0x0000000101c0a39e $s2o211AppDelegateC5$mainyyFZ + 46
40 o2 0x0000000101c0a4c9 main + 41
41 libdyld.dylib 0x00007fff2025abbd start + 1
42 ??? 0x0000000000000001 0x0 + 1
)
libc++abi: terminating with uncaught exception of type NSException
*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<o2.ViewController 0x7fa9f0706c90> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key b.'
terminating with uncaught exception of type NSException
CoreSimulator 757.5 - Device: iPhone 8 (471D3BE9-5C7E-49C1-970B-3C3BF7226727) - Runtime: iOS 14.5 (18E182) - DeviceType: iPhone 8
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var L: UITextField!
@IBOutlet weak var M_MPa: UITextField!
@IBOutlet weak var L_MPa: UITextField!
@IBOutlet weak var l_m: UITextField!
@IBOutlet weak var gus: UILabel!
@IBOutlet weak var last_m: UILabel!
@IBOutlet weak var last_L: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
L.placeholder = "内積量(L)を入力してください"
M_MPa.placeholder = "maxの充填圧力(MPa)を入力してください"
L_MPa.placeholder = "残り充填圧力(MPa)を入力してください"
l_m.placeholder = "患者使用流(L/分)を入力してください"
}
@IBAction func calcurate(_ sender: Any) {
let double_g = Double(L_MPa.text!)
let double_c = Double(l_m.text!)
let double_a = Double(L.text!)
let double_b = Double(M_MPa.text!)
gus.text = calculation1(L_MPa:double_g!, l_m:double_c!,L: double_a!, M_MPa:double_b!)
last_m.text = calculation2(L_MPa:double_g!, l_m:double_c!,L: double_a!, M_MPa:double_b!)
last_L.text = calculation3(L_MPa:double_g!, l_m:double_c!,L: double_a!, M_MPa:double_b!)
}
func calculation1(L_MPa:Double, l_m:Double,L:Double, M_MPa:Double)-> String{
let a = L
let b = M_MPa
var d = (a*b*10.0)//varはletではできない書き換えができる
d = (a*b*10.0)
return d.description
}
func calculation2(L_MPa:Double, l_m:Double,L:Double, M_MPa:Double)-> String{
let c = l_m
let a = L
let b = M_MPa
let d = (a*b*10.0)
var e = (d/c)
e = (d/c)
return e.description
}
func calculation3(L_MPa:Double, l_m:Double,L:Double, M_MPa:Double)-> String{
let g = L_MPa
let a = L
let b = M_MPa
var d = (a*b*10.0)
d = (a*b*10.0)
var f = d*(g/b)
f = d*(g/b)
return f.description
}
}