Skip to content

Commit

Permalink
Update code for newer Swift 5
Browse files Browse the repository at this point in the history
  • Loading branch information
abelsanchezali committed Sep 30, 2021
1 parent e9ecaba commit 55ca397
Show file tree
Hide file tree
Showing 139 changed files with 1,120 additions and 994 deletions.
1 change: 1 addition & 0 deletions Source/Document/Addin/Childs/DocumentChildsProcessor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import Foundation

@objc
public protocol DocumentChildsProcessor {
func processDocument(childs: DocumentChildVisitor)
}
2 changes: 1 addition & 1 deletion Source/Document/Addin/Childs/ObjectTransformable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@

import Foundation

public protocol ObjectTransformable: class {
public protocol ObjectTransformable: AnyObject {
func transformToObjects() -> [Any]?
}
2 changes: 1 addition & 1 deletion Source/Document/Addin/Childs/ValueProviderProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ import Foundation

public protocol ValueProviderProtocol {
func getPresentedValue() -> Any?
}
}
2 changes: 1 addition & 1 deletion Source/Document/Addin/Properties/NSValueConvertible.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ import Foundation

public protocol NSValueConvertible {
func convertToNSValue() -> NSValue?
}
}
32 changes: 31 additions & 1 deletion Source/Document/Addin/Properties/Numeric.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,39 +12,69 @@ import CoreGraphics
// MARK: IntMaxConvertible Protocol

protocol IntMaxConvertible {
func toIntMax() -> IntMax
func toIntMax() -> Int64
}

// MARK: IntMaxConvertible for Integer Types

extension Int: IntMaxConvertible {
func toIntMax() -> Int64 {
return Int64(self)
}
}

extension UInt: IntMaxConvertible {
func toIntMax() -> Int64 {
return Int64(self)
}
}

extension Int8: IntMaxConvertible {
func toIntMax() -> Int64 {
return Int64(self)
}
}

extension Int16: IntMaxConvertible {
func toIntMax() -> Int64 {
return Int64(self)
}
}

extension Int32: IntMaxConvertible {
func toIntMax() -> Int64 {
return Int64(self)
}
}

extension Int64: IntMaxConvertible {
func toIntMax() -> Int64 {
return Int64(self)
}
}

extension UInt8: IntMaxConvertible {
func toIntMax() -> Int64 {
return Int64(self)
}
}

extension UInt16: IntMaxConvertible {
func toIntMax() -> Int64 {
return Int64(self)
}
}

extension UInt32: IntMaxConvertible {
func toIntMax() -> Int64 {
return Int64(self)
}
}

extension UInt64: IntMaxConvertible {
func toIntMax() -> Int64 {
return Int64(self)
}
}

// MARK: Int
Expand Down
2 changes: 1 addition & 1 deletion Source/Document/Addin/Properties/PropertyHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Foundation

class PropertyHelper {

@discardableResult public static func setProperty(_ instance: Any, name: String, value: Any?, hasPath: Bool = false) -> Bool {
if let accesible = instance as? KeyValueAccesible {
return hasPath ?
Expand Down
2 changes: 1 addition & 1 deletion Source/Document/Cache/DocumentCacheProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import Foundation

public protocol DocumentCacheProtocol: class {
public protocol DocumentCacheProtocol: AnyObject {
func getDocumentWithKey(_ key: AnyObject) -> DataDocument?
func saveDocumentWithKey(_ key: AnyObject, document: DataDocument) -> Bool
func removeDocumentWithKey(_ key: AnyObject) -> Bool
Expand Down
2 changes: 1 addition & 1 deletion Source/Document/Core/DefaultConstructor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@

import Foundation

public protocol DefaultConstructor: class {
public protocol DefaultConstructor: AnyObject {
init()
}
2 changes: 1 addition & 1 deletion Source/Document/Core/DefaultTextDeserializerService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ open class DefaultTextDeserializerService: TextDeserializerServiceProtocol {
open func getValueAndMutability(_ text: String) -> (Any?, Bool) {
var value: Any? = nil
if text.hasPrefix("@") {
let key = text.substring(from: text.characters.index(text.startIndex, offsetBy: 1))
let key = text.substring(from: text.index(text.startIndex, offsetBy: 1))
value = resolveValueForKey(key)
if let value = value {
return (value, false)
Expand Down
2 changes: 1 addition & 1 deletion Source/Document/Core/DocumentBuilder+Build.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ extension DocumentBuilder {
- Parameter path: Path to Document.
- Parameter options: Options to be used during build process.
- Returns: An instance of type T described in document.
*/
public func load<T>(_ path: String, options: BuildOptions? = nil) -> T? {
Expand Down
8 changes: 4 additions & 4 deletions Source/Document/Core/DocumentFactory+Build.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import UIKit

public extension DocumentFactory {

public func buildObject(_ options: InstantiationOptions? = nil) -> Any? {
func buildObject(_ options: InstantiationOptions? = nil) -> Any? {
let options = options ?? InstantiationOptions()
return buildNode(document.baseNode, instance: options.baseInstance)
}

public func build<T>(_ options: InstantiationOptions? = nil) -> T? {
func build<T>(_ options: InstantiationOptions? = nil) -> T? {
let options = options ?? InstantiationOptions()
guard let _ = document.baseNode.referenceType as? T.Type else {
if options.verbose {
Expand All @@ -28,15 +28,15 @@ public extension DocumentFactory {
return buildNode(document.baseNode, instance: options.baseInstance) as? T
}

public func buildResources(_ options: InstantiationOptions? = nil) -> Resources? {
func buildResources(_ options: InstantiationOptions? = nil) -> Resources? {
return build(options)
}
}

// MARK: UIKit

public extension DocumentFactory {
public func buildView(_ options: InstantiationOptions? = nil) -> UIView? {
func buildView(_ options: InstantiationOptions? = nil) -> UIView? {
return build(options)
}
}
4 changes: 2 additions & 2 deletions Source/Document/Core/DocumentFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Foundation
public class DocumentFactory: NSObject {

static let DomainsValuesPrefix = "domains."
static let DomainsValuesPrefixLength = DocumentFactory.DomainsValuesPrefix.characters.count
static let DomainsValuesPrefixLength = DocumentFactory.DomainsValuesPrefix.count

public let document: DataDocument
public let builder: DocumentBuilder
Expand Down Expand Up @@ -166,7 +166,7 @@ public class DocumentFactory: NSObject {

func valueForKey(_ key: String) -> Any? {
if key.hasPrefix(DocumentFactory.DomainsValuesPrefix) {
return domainForPrefix(key.substring(from: key.characters.index(key.startIndex, offsetBy: DocumentFactory.DomainsValuesPrefixLength)))
return domainForPrefix(key.substring(from: key.index(key.startIndex, offsetBy: DocumentFactory.DomainsValuesPrefixLength)))
}
if let resourceValue = document.resources[key] {
return resourceValue
Expand Down
2 changes: 1 addition & 1 deletion Source/Document/Core/KeyValueResolverProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@

import Foundation

public protocol KeyValueResolverProtocol: class {
public protocol KeyValueResolverProtocol: AnyObject {
func resolveValue(for key: String) -> Any?
}
4 changes: 2 additions & 2 deletions Source/Document/Core/PropertyCollection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ open class PropertyCollection: Sequence {
propertiesByName[property.name] = property
}

open func makeIterator() -> LazyMapIterator<DictionaryIterator<String, Property>, Property> {
return propertiesByName.values.makeIterator()
open func makeIterator() -> Dictionary<String, Property>.Values.Iterator {
return propertiesByName.values.makeIterator();
}
}
4 changes: 2 additions & 2 deletions Source/Document/Core/TextDeserializer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ public protocol TextDeserializer {
}

public extension TextDeserializer {
public static func isDeserializedInstanceMutable() -> Bool {
static func isDeserializedInstanceMutable() -> Bool {
return false
}
}

public extension TextDeserializer {
public static func deserialize(text: String?) -> Any? {
static func deserialize(text: String?) -> Any? {
return deserialize(text: text, service: DefaultTextDeserializerService.shared)
}
}
Expand Down
4 changes: 2 additions & 2 deletions Source/Document/Core/TextDeserializerServiceProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public protocol TextDeserializerServiceProtocolDelegate: KeyValueResolverProtoco
func resolveDomain(for prefix: String) -> String?
}

public protocol TextDeserializerServiceProtocol: class {
weak var delegate: TextDeserializerServiceProtocolDelegate? { get set }
public protocol TextDeserializerServiceProtocol: AnyObject {
var delegate: TextDeserializerServiceProtocolDelegate? { get set }

func parseValidWordsArray(from text: String) -> [String]?
func parseValidDoubleArray(from text: String) -> [Double]?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import Foundation

public protocol DataDeserializerProtocol: class, DefaultConstructor {
public protocol DataDeserializerProtocol: DefaultConstructor {
static var identifier: String { get }
func loadData(from path: String, options: DocumentOptions) -> DataNode?
}
6 changes: 3 additions & 3 deletions Source/Document/Deserializer/XMLDataDeserializer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ class XMLDataDeserializerNSXMLParserDelegate: NSObject, XMLParserDelegate {
}

if namespace.hasPrefix("@") {
let key = namespace.substring(from: namespace.characters.index(namespace.startIndex, offsetBy: 1))
let key = namespace.substring(from: namespace.index(namespace.startIndex, offsetBy: 1))
// Resolve namespaces with module name
if let match = Constants.moduleWithNameExpresion?.firstMatch(in: key,
options: NSRegularExpression.MatchingOptions(rawValue: 0),
range: NSMakeRange(0, key.characters.count)),
let nameParameter = key.substring(match.rangeAt(1)) {
range: NSMakeRange(0, key.count)),
let nameParameter = key.substring(match.range(at:1)) {
return options.resolveNamespaceWithName(nameParameter)
}
// Fallback to defined namespaces
Expand Down
8 changes: 5 additions & 3 deletions Source/Document/Helpers/ReflectionHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ open class ReflectionHelper {
}
let bundlePath = b.bundlePath
if path.hasPrefix(bundlePath) {
let bundlePathLength = bundlePath.characters.count
let bundlePathLength = bundlePath.count
if bundlePathLength > best {
best = bundlePathLength
bundle = b
Expand Down Expand Up @@ -137,8 +137,10 @@ open class ReflectionHelper {
}

public class func swizzleMethod(_ originalType: AnyClass, originalSelector: Selector, _ swizzledType: AnyClass, swizzledSelector: Selector) {
let originalMethod = class_getInstanceMethod(originalType, originalSelector)
let swizzledMethod = class_getInstanceMethod(swizzledType, swizzledSelector)
guard let originalMethod = class_getInstanceMethod(originalType, originalSelector),
let swizzledMethod = class_getInstanceMethod(swizzledType, swizzledSelector) else {
return;
}

let didAddMethod = class_addMethod(originalType, originalSelector, method_getImplementation(swizzledMethod), method_getTypeEncoding(swizzledMethod))

Expand Down
Loading

0 comments on commit 55ca397

Please sign in to comment.