小编mra*_*iao的帖子

如何在现有UIKit类(如UIColor)的扩展中添加初始值设定项?

Swift文档说可以在扩展中添加初始化程序,文档中的示例是关于向结构添加初始化程序.Xcode无法识别UIColor我的便捷初始化程序中的指定初始值设定项:

extension UIColor {
  convenience init(rawValue red: CGFloat, green g: CGFloat, blue b: CGFloat, alpha a: CGFloat) {

    // Can not find out the designated initializer here
    self.init()

  }
}
Run Code Online (Sandbox Code Playgroud)

有解决方案吗

uicolor swift

27
推荐指数
1
解决办法
2万
查看次数

如何使用self和enum在Swift中设置条件断点的条件?

我有一个HTTP方法的枚举:

enum HTTPMethod: String {
  case GET = "GET"
  case POST = "POST"
}
Run Code Online (Sandbox Code Playgroud)

我有一个请求类和一个请求包装类:

class Request {
  let method: HTTPMethod = .GET
}

class RequestWrapper {
  let request: Request

  func compareToRequest(incomingRequest: NSURLRequest) -> Bool {

     // Next line is where the conditional breakpoint set.
     return request.method.rawValue == incomingRequest.HTTPMethod
  }
}
Run Code Online (Sandbox Code Playgroud)

我在行上设置了一个条件断点:

return request.method.rawValue == incomingRequest.HTTPMethod
Run Code Online (Sandbox Code Playgroud)

条件:

self.request.method == HTTPMethod.POST
Run Code Online (Sandbox Code Playgroud)

然后调试器在该行停止并显示错误消息:

Stopped due to an error evaluating condition of breakpoint 1.1:     
"self.request.method == HTTPMethod.POST"
Couldn't parse conditional expression:
<EXPR>:1:1: error: …
Run Code Online (Sandbox Code Playgroud)

debugging enums ios lldb swift

13
推荐指数
1
解决办法
2028
查看次数

使用storyboard时如何对第一屏的视图控制器进行依赖注入?

手动编写代码时,我们可以通过AppDelegate 中的构造函数注入将依赖项注入到 rootViewController 中:

UIViewController *vc = [[SomeViewController alloc] initWithDependency: dependency];
self.window.rootViewController = vc;
Run Code Online (Sandbox Code Playgroud)

但是,我找不到在使用Storyboard时注入依赖项的方法。将它们注入awakeFromNibviewDidLoad等等似乎是不合适的。

那可以注射吗?

dependency-injection objective-c storyboard ios

5
推荐指数
1
解决办法
1505
查看次数