iosWebViewFix/ios/Classes/IWebViewSettings.swift

47 lines
1.2 KiB
Swift
Raw Normal View History

//
// Options.swift
2019-11-29 15:59:18 +00:00
// flutter_inappwebview
//
// Created by Lorenzo on 26/09/18.
//
import Foundation
@objcMembers
2022-04-19 23:30:45 +00:00
public class IWebViewSettings<T>: NSObject {
override init(){
super.init()
}
2022-04-19 23:31:14 +00:00
func parse(settings: [String: Any?]) -> IWebViewSettings {
for (key, value) in settings {
if !(value is NSNull), value != nil, self.responds(to: Selector(key)) {
self.setValue(value, forKey: key)
}
}
2018-10-15 23:27:58 +00:00
return self
}
2018-10-17 23:38:36 +00:00
func toMap() -> [String: Any?] {
2022-04-19 23:31:14 +00:00
var settings: [String: Any?] = [:]
2018-10-17 23:38:36 +00:00
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)
2022-04-19 23:31:14 +00:00
settings[name] = self.value(forKey: name)
2018-10-17 23:38:36 +00:00
}
free(properties)
2022-04-19 23:31:14 +00:00
return settings
2018-10-17 23:38:36 +00:00
}
2022-04-19 23:31:14 +00:00
func getRealSettings(obj: T?) -> [String: Any?] {
let realSettings: [String: Any?] = toMap()
return realSettings
}
}