Skip to content
This repository has been archived by the owner on Oct 4, 2019. It is now read-only.

Using dyci

PaulTaykalo edited this page Nov 10, 2012 · 23 revisions

At first, please, look to example, that goes with the main project. Really:)

#Adding sources There's plenty ways to add dyci to your project, but these two are the most preferable

##As subproject Just grab dyci project to your workspace Add it as dependecy in your project Adding as static library

##As Cocoa Pod TBD

#Enabling Dyci In your applocation entry point (AppDelegate), write next line
[SFDynamicCodeInjection enable];
Done. You successfully enabled dyci.

##First-time recompilation. At the same first time you need clean your project and recompile. In other case, you won't be able to use dyci, since, it wont be able to compile your file correctly

#Using!

##Recompile and Inject If you successfully installed dyci, you have additional menu item in "Product" menu in Xcode, with "Recompile and Inject ^X" name.
Note that, you need your application to be running, to use this tool :)
Each time, you pressing '^X', your class is being injected to your running application.
If you have errors in your code, then Xcode will fail and show alert with notification that code cannot be compiled.
If all went good, you see alot of information about injection in Console. Read it carefully. At least first time.

##Update on class injection Sometimes, default code injection doesn't allow you to correctly update objects that was already created.
It's because they already passed "initialization phase", i.e. view was already loaded to ViewController, controller had already called initWithNibName: method
For this case, you need to implement -(void)updateOnClassInjection in class, that you're going to inject.
This method will be called on each class injection on all instances of this class, and instances of this class subclasses.
For example, in dyci example, you could see this kind of code:
`- (void)viewDidLoad {
[super viewDidLoad];
[self createGUI];
} ...

  • (void)updateOnClassInjection {

    // "Emulating" viewDidLoad method
    // Cleaning up all views and
    NSArray * subviews = [[self view] subviews];
    for (UIView * v in subviews) {
    [v removeFromSuperview];
    }

    [self createGUI];
    }
    `

Clone this wiki locally