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

iOSアプリ開発でLLDBでView要素を操作する

More than 1 year has passed since last update.

色々なところに書いてあるが自分用のメモ

LLDBからViewのアドレスを取得する

(lldb) expr -l swift -O -- import UIKit
(lldb) expr -l swift -O -- UIApplication.shared.keyWindow!.rootViewController!.view!.value(forKey: "recursiveDescription")!

<UILayoutContainerView: 0x7f9a3f41def0; frame = (0 0; 375 667); autoresize = W+H; gestureRecognizers = <NSArray: 0x6080004546d0>; layer = <CALayer: 0x600000036360>>
   | <UINavigationTransitionView: 0x7f9a3f41ec70; frame = (0 0; 375 667); clipsToBounds = YES; autoresize = W+H; layer = <CALayer: 0x60000003bca0>>
   |    | <UIViewControllerWrapperView: 0x7f9a3f50b4a0; frame = (0 0; 375 667); autoresize = W+H; layer = <CALayer: 0x604000039520>>
   |    |    | <UIView: 0x7f9a3f70ce10; frame = (0 0; 375 667); autoresize = W+H; layer = <CALayer: 0x60c0000344e0>>
   |    |    |    | <UIScrollView: 0x7f9a40017000; frame = (0 64; 375 603); clipsToBounds = YES; autoresize = RM+BM; gestureRecognizers = <NSArray: 0x60c000241980>; layer = <CALayer: 0x60c0000367e0>; contentOffset: {0, 0}; contentSize: {375, 603}; adjustedContentInset: {0, 0, 0, 0}>
   |    |    |    |    | <UIView: 0x7f9a3f70d110; frame = (8 8; 359 587); autoresize = RM+BM; layer = <CALayer: 0x60c000037dc0>>
   |    |    |    |    |    | <UILabel: 0x7f9a43401770; frame = (30 30; 299 527); text = 'Many scientists opposed h...'; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x604000099870>>
   |    |    |    |    | <UIImageView: 0x7f9a3f5135d0; frame = (369.5 593; 2.5 7); alpha = 0; opaque = NO; autoresize = LM; userInteractionEnabled = NO; layer = <CALayer: 0x60400003cb40>>
   |    |    |    |    | <UIImageView: 0x7f9a3f50d1d0; frame = (365 597.5; 7 2.5); alpha = 0; opaque = NO; autoresize = TM; userInteractionEnabled = NO; layer = <CALayer: 0x60400003ca60>>
   |    |    |    | <_UILayoutGuide: 0x7f9a3f70e170; frame = (0 0; 0 64); hidden = YES; layer = <CALayer: 0x60c000037c60>>
   |    |    |    | <_UILayoutGuide: 0x7f9a3f70e370; frame = (0 667; 0 0); hidden = YES; layer = <CALayer: 0x60c000037c20>>
   | <UINavigationBar: 0x7f9a3f40ebf0; frame = (0 20; 375 44); opaque = NO; autoresize = W; layer = <CALayer: 0x6000000363e0>>
   |    | <_UIBarBackground: 0x7f9a3f40f600; frame = (0 -20; 375 64); userInteractionEnabled = NO; layer = <CALayer: 0x600000036040>>
   |    |    | <UIImageView: 0x7f9a3f4102f0; frame = (0 64; 375 0.5); userInteractionEnabled = NO; layer = <CALayer: 0x600000036440>>
   |    |    | <UIVisualEffectView: 0x7f9a3f410520; frame = (0 0; 375 64); layer = <CALayer: 0x600000036460>>
   |    |    |    | <_UIVisualEffectBackdropView: 0x7f9a3f601e40; frame = (0 0; 375 64); autoresize = W+H; userInteractionEnabled = NO; layer = <UICABackdropLayer: 0x608000423bc0>>
   |    |    |    | <_UIVisualEffectSubview: 0x7f9a3f603f20; frame = (0 0; 375 64); autoresize = W+H; userInteractionEnabled = NO; layer = <CALayer: 0x6080004248a0>>
   |    | <_UINavigationBarLargeTitleView: 0x7f9a3f40f860; frame = (0 0; 0 44); clipsToBounds = YES; alpha = 0; hidden = YES; layer = <CALayer: 0x600000036840>>
   |    |    | <UILabel: 0x7f9a3f5163e0; frame = (0 0; 0 0); userInteractionEnabled = NO; layer = <_UILabelLayer: 0x60400009a720>>
   |    | <_UINavigationBarContentView: 0x7f9a3f4111c0; frame = (0 0; 375 44); clipsToBounds = YES; layer = <CALayer: 0x6000000364c0>>
   |    |    | <_UIButtonBarButton: 0x7f9a3f429b60; frame = (0 0; 65 44); layer = <CALayer: 0x60000003b0e0>>
   |    |    |    | <_UIModernBarButton: 0x7f9a3f607260; frame = (8 11.5; 13 21); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x608000425080>>
   |    |    |    |    | <UIImageView: 0x7f9a3f70f060; frame = (0 0; 13 21); clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x60c000037860>>
   |    |    |    | <_UIBackButtonContainerView: 0x7f9a3f619260; frame = (0 0; 65 44); autoresize = W+H; userInteractionEnabled = NO; layer = <CALayer: 0x6080004279c0>>
   |    |    |    |    | <_UIModernBarButton: 0x7f9a3f606f20; frame = (27 9; 38 23.5); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x608000033200>>
   |    |    |    |    |    | <UIButtonLabel: 0x7f9a3f613180; frame = (-1.5 3; 38 20.5); text = 'Back'; opaque = NO; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x608000092930>>
   |    | <_UINavigationBarModernPromptView: 0x7f9a3f418590; frame = (0 0; 0 44); alpha = 0; hidden = YES; layer = <CALayer: 0x600000037c60>>
   |    |    | <UILabel: 0x7f9a3f418bd0; frame = (0 25.5; 0 0); text = ''; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x600000097de0>>
   |    |    |    |    |    | <UILabel: 0x7f9a43401770; frame = (30 30; 299 527); text = 'Many scientists opposed h...'; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <_UILabelLayer: 0x604000099870>>

↑からアドレスを取得できる

View UI HierarckyからViewのアドレスを取得する

Print Descriptionからアドレスを取得できる

スクリーンショット 2018-07-24 16.47.31.png

unsafeBitCastでViewオブジェクトを取得

オブジェクトを操作できるので、ここでView要素を操作できる

(lldb) expr -l swift -- unsafeBitCast(0x00007f9667c21660, UILabel.self).text = "Hello, world."

参考

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