LoginSignup
2

More than 3 years have passed since last update.

Storyboardで設置したUIを custom classで編集した時の注意点[Swift](exc_bad_instruction (code=exc_i386_invop subcode=0x0))

Last updated at Posted at 2019-08-06

概要

StoryboardでUI(hogehogeViewとする)を設置し

@IBOutlet weak var hogehogeView: hugahugaCustomView!

・こんな風にコード側とも連携を取り(&しっかりとcustom classを参照)

hugahugaCustomView.swift
import UIKit

class hugahugaCustomView: UIView {
    //やりたい処理
}

そして実行!

問題と解決策

問題

実行するとこんなエラーが、、、、

exc_bad_instruction (code=exc_i386_invop subcode=0x0)

こいつはいろんなパターンで出るようですが
UIが繋がってません系のミスで多いようですね
(※これ以外にある場合はのちに追記)

参考
Xcode - EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)と表示されアプリがクラッシュされてしまいます。|teratail
iOS - 【エラーの対処法がわかりません】exc_bad_instruction (code=exc_i386_invop subcode=0x0)|teratail

解決策

storyboard側でもしっかりとcustom classを参照しましょう
storyboardでUI扱うときのcustomclass.png

結論

Storyboardで設置したUIをcustom classで編集している場合の注意点をまとめると
@IB...で定義した後Storyboard側と連携を取る(右クリック&ドラッグでつなぐ)
@IB...の定義でcustom classを参照する
Storyboard側でもcustom classを参照する

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2