8
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Xcode11.2でStoryboardのUITextViewがcrashする

Posted at

エラー内容

*** 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

8
5
0

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
8
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?