Skip to main content

Posts

Showing posts with the label Dependency injection

Casting and testing for class conformance in Swift

EDIT: The previous answers alluded to in the comments can be used to solve the problem, although the question there lay in determining a Type from an Any vs my question here, which was how to determine if any given Type was a reference type and how to safely conform said type to AnyObject. So I have a new dependency injection framework, Factory . Factory allows for scoped instances, basically allowing you to cache services once they're created. And one of those scopes is shared . Any instance shared will be cached and returned just as long as someone in the outside world maintains a strong reference to it. After the last reference releases the object the cache releases the object and a new instance will be created on the next resolution. This is implemented, obviously, as simply maintaining a weak reference to the created object. If the weak reference is nil it's time to create a new object. And therein lies the problem Weak references can only apply to reference type...