我创建了一个超级简单的协议:
protocol IndependentProtocol {}
Run Code Online (Sandbox Code Playgroud)
和服务:
class IndependentService: IndependentProtocol {}
Run Code Online (Sandbox Code Playgroud)
以及以下Swinject注册工作:
defaultContainer.register( IndependentProtocol.self )
{
_ in IndependentService()
}
Run Code Online (Sandbox Code Playgroud)
但以下一项则不然:
defaultContainer.register( IndependentProtocol.self )
{
_ in IndependentService()
}.inObjectScope( .Container )
Run Code Online (Sandbox Code Playgroud)
给出的错误是:
Ambiguous reference to member 'register(_:name:factory:)'
Run Code Online (Sandbox Code Playgroud)
有趣的是,以下工作(即:带有参数的服务可以在.container范围内注册):
defaultContainer.register( AnotherProtocol.self )
{
r in AnotherService(
signals: r.resolve( AnotherService.self )!
)
}.inObjectScope( .container )
Run Code Online (Sandbox Code Playgroud)
我读过这个类似的问题,这没有帮助:Swinject - 对成员的模糊引用
谢谢大家。
例如,这有效:
guard condition == true else { return }
Run Code Online (Sandbox Code Playgroud)
哪个好,但会造成无声的失败.什么是好的是有一个静态功能,可以输出反馈,同时也返回.就像是:
guard condition == true else { stop("condition was false") }
Run Code Online (Sandbox Code Playgroud)
我在这里生活在梦乡还是可能?
当然,我认识到以下是可能的:
guard condition == true else {
print("condition was false")
return
}
Run Code Online (Sandbox Code Playgroud)
但样板很重,有点难看.我到处都有警卫声明,这种代码是:1.有用; 但是2.会将我的代码批量化,例如,最低10%.
我知道这是我的乌托邦,但我更喜欢优雅的解决方案.任何人?
这段代码:
let rect = CGRectMake( 0.0, 0.0, 16.0, 16.0 )
let context = UIGraphicsGetCurrentContext()
UIGraphicsBeginImageContext( rect.size )
CGContextSetFillColorWithColor( context, color.CGColor )
CGContextFillRect( context, rect )
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
Run Code Online (Sandbox Code Playgroud)
正在抛出这些错误:
MakeImage[60890] <Error>: CGContextSetFillColorWithColor: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
MakeImage[60890] <Error>: CGContextFillRects: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
Run Code Online (Sandbox Code Playgroud)
CGRect 大小似乎很好,其他帖子建议作为问题。那么还有什么设置不正确,请?谢谢你。