-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
Copy pathOptions.swift
executable file
·46 lines (38 loc) · 1.14 KB
/
Options.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
//
// Options.swift
// flutter_inappwebview
//
// Created by Lorenzo on 26/09/18.
//
import Foundation
@objcMembers
public class Options<T>: NSObject {
override init(){
super.init()
}
func parse(options: [String: Any?]) -> Options {
for (key, value) in options {
if value != nil, !(value is NSNull), self.responds(to: Selector(key)) {
self.setValue(value, forKey: key)
}
}
return self
}
func toMap() -> [String: Any?] {
var options: [String: Any?] = [:]
var counts = UInt32();
let properties = class_copyPropertyList(object_getClass(self), &counts);
for i in 0..<counts {
let property = properties?.advanced(by: Int(i)).pointee;
let cName = property_getName(property!);
let name = String(cString: cName)
options[name] = self.value(forKey: name)
}
free(properties)
return options
}
func getRealOptions(obj: T?) -> [String: Any?] {
let realOptions: [String: Any?] = toMap()
return realOptions
}
}