Help us understand the problem. What is going on with this article?

Xcode11.2でStoryboardのUITextViewがcrashする

エラー内容

*** Terminating app due to uncaught exception 'NSInvalidUnarchiveOperationException', reason: 'Could not instantiate class named _UITextLayoutView because no class named _UITextLayoutView was found; the class needs to be defined in source code or linked in from a library (ensure the class is part of the correct target)'

発生条件

  • Xcodeのバージョンは11.2
  • StoryboardのUITextViewを使っている
  • 実機端末のosバージョンが13.2以下

解決方法

Xcodeをダウングレードする

11.2以外のバージョンを使う

simulatorで検証する

この問題は実機だけで発生する

_UITextLayoutView を動的に追加する

手順

UITextViewFixer.hを作る

UITextViewFixer.h
#import <Foundation/Foundation.h>

@interface UITextViewFixer : NSObject
    + (void)executeWorkaround;
@end

UITextViewFixer.mを作る

UITextViewFixer.m
#import "UITextViewFixer.h"
#import  <objc/runtime.h>

@implementation UITextViewFixer

+ (void)executeFixer {
    if (@available(iOS 13.2, *)) {
        // やることがない
    }
    else {
        const char *className = "_UITextLayoutView";
        Class cls = objc_getClass(className);
        if (cls == nil) {
            cls = objc_allocateClassPair([UIView class], className, 0);
            objc_registerClassPair(cls);
        }
    }
}

@end

appDelegateに入れる

didFinishLaunchingWithOptionsの中に
[UITextViewFixer executeFixer];
を追加する

参考リンク

https://forums.developer.apple.com/thread/125287
https://stackoverflow.com/questions/58657087/after-upgrading-to-xcode-11-2-from-xcode-11-1-app-crashes-due-to-uitextlayoutv

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away