66[ ![ Carthage compatible] ( https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat )] ( https://github.com/Carthage/Carthage )
77
88# ObjectiveKit
9- ObjectiveKit provides a Swift- friendly API for a set of powerful Objective C runtime functions.
9+ ObjectiveKit provides a Swift friendly API for a set of powerful Objective C runtime functions.
1010
1111## Usage
1212
@@ -39,17 +39,15 @@ let protocols = mapViewClass.allProtocols() // Returns an array of protocols.
3939
4040### Modifying classes at runtime
4141
42- ObjectiveKit to add / exchange methods for a class at runtime.
43-
44- You can add a pre-existing function from another class to your Objective class:
42+ Add a pre-existing function from another class to your Objective class:
4543``` swift
4644let viewClass = ObjectiveClass< UIView> ()
4745viewClass.addSelectorToClass (#selector (testSelector), fromClass : self .classForCoder )
4846let view = UIView ()
4947view.perform (#selector (testSelector))
5048```
5149
52- Alternatively, you can add a method by providing a custom implementation with a closure:
50+ Add a method by providing a custom implementation with a closure:
5351``` swift
5452let viewClass = ObjectiveClass< UIView> ()
5553viewClass.addMethodToClass (closureName, implementation : {
@@ -65,6 +63,16 @@ let viewClass = ObjectiveClass<UIView>()
6563viewClass.exchangeSelector (#selector (UIView.layoutSubviews ), with : #selector (UIView.xxx_layoutSubviews ))
6664```
6765
66+ ### Creating classes at runtime
67+
68+ Lastly, you can also create a custom ObjC class at runtime:
69+ ``` swift
70+ let runtimeClass = RuntimeClass (superclass : UIView.self )
71+ runtimeClass.addIvar (ivarName, type : .Float )
72+ let runtimeObject = runtimeClass.allocate ()
73+ runtimeObject.setValue (4.0 , forKey : ivarName)
74+ ```
75+
6876## Setting up
6977
7078### Setting up with [ CocoaPods] ( http://cocoapods.org/?q=ObjectiveKit )
0 commit comments