LoginSignup
9
3

More than 5 years have passed since last update.

Xcodeでinjectionforxcodeを使って見た

Last updated at Posted at 2018-03-03

はじめに

injectionforxcodetとは

Runtime Code Injection for Objective-C & Swift

  • アプリを実行中に動的にコードを追加できるツールです

環境

Apple Swift version 4.0.3 (swiftlang-900.0.74.1 clang-900.0.39.2)
Target: x86_64-apple-macosx10.9
Xcode Version 9.2 (9C40b)

導入方法

  1. johnholdsworth.com/injectionからXcode9に対応したものをダウンロードする
  2. ダウンロードしたzipを解凍し、インストールする
  3. システム環境設定→ キーボード → ショートカットでinject Sourceのショートカットキーを有効にする スクリーンショット 2018-03-03 9.41.25.png

実装

  1. runtime時に動的に追加したいUIViewControllerに@objc func injected()あるいはINJECTION_BUNDLE_NOTIFICATIONをnameにしたNotificationCenterを追加
  2. アプリを起動させる
  3. 追加したいコードを追加
  4. 変更したファイルを保存する
  5. Control + =のショートカットキーを押すと動的に追加したコードが実行される

サンプルコード

参考リンク

9
3
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
9
3