Skip to content

Commit

Permalink
Add more dubug descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
SpectralDragon committed Nov 28, 2019
1 parent 9279615 commit b24bfd7
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 4 deletions.
8 changes: 7 additions & 1 deletion Sources/SwiftDI/DIObject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

class DIObject {
class DIObject: CustomDebugStringConvertible {

let lazy: Lazy
let type: Any.Type
Expand All @@ -26,4 +26,10 @@ class DIObject {
}

var lifeCycle: DILifeCycle = SwiftDI.Defaults.lifeCycle

var debugDescription: String {
let address = Unmanaged.passUnretained(self).toOpaque()
let type = String(describing: self.type)
return String(format: "[DIObject <%@>] %@ - %@", address.debugDescription, type, self.lifeCycle.debugDescription)
}
}
6 changes: 5 additions & 1 deletion Sources/SwiftDI/Resolver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ class DIResolver {
}

func resolve<T>(bundle: Bundle? = nil) -> T {
return makeObject(for: T.self, bundle: bundle, usingObject: nil) as! T
if let object = makeObject(for: T.self, bundle: bundle, usingObject: nil) {
return object as! T
} else {
fatalError("Couldn't found object for type \(T.self)")
}
}

func makeObject(for type: Any.Type, bundle: Bundle?, usingObject: DIObject?) -> Any? {
Expand Down
11 changes: 11 additions & 0 deletions Sources/SwiftDI/SwiftDI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,14 @@ public enum DILifeCycle {
/// Dependency instance is created one per object graph.
case objectGraph
}

extension DILifeCycle: CustomDebugStringConvertible {
public var debugDescription: String {
switch self {
case .single: return "single"
case .prototype: return "protorype"
case .weakSingle: return "weakSingle"
case .objectGraph: return "objectGraph"
}
}
}
8 changes: 7 additions & 1 deletion Sources/SwiftDI/Utils/Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,18 @@

import Foundation

class Weak<T: AnyObject> {
class Weak<T: AnyObject>: CustomDebugStringConvertible {
weak var value: T?

init(value: T) {
self.value = value
}

var debugDescription: String {
let address = Unmanaged.passUnretained(self).toOpaque()
let type = String(describing: T.self)
return String(format: "<Weak<%@>>: %@, value: %@", type, address.debugDescription, value.debugDescription)
}
}

class Lazy {
Expand Down
3 changes: 2 additions & 1 deletion SwiftDI.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ Pod::Spec.new do |s|
s.source = { :git => 'https://github.com/LiteCode/SwiftDI.git', :tag => s.version.to_s }

s.ios.deployment_target = '13.0'
s.macos.deployment_target = '10.15'
s.swift_version = '5.1'
s.source_files = 'Sources/SwiftDI/**/*.{swift}'

end


0 comments on commit b24bfd7

Please sign in to comment.