Skip to content

Commit 65b9560

Browse files
committed
README update
1 parent 78f1523 commit 65b9560

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

README.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
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
4644
let viewClass = ObjectiveClass<UIView>()
4745
viewClass.addSelectorToClass(#selector(testSelector), fromClass: self.classForCoder)
4846
let view = UIView()
4947
view.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
5452
let viewClass = ObjectiveClass<UIView>()
5553
viewClass.addMethodToClass(closureName, implementation: {
@@ -65,6 +63,16 @@ let viewClass = ObjectiveClass<UIView>()
6563
viewClass.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

Comments
 (0)