【发布时间】:2015-07-03 23:22:59
【问题描述】:
我有一个 HTTP 方法的枚举:
enum HTTPMethod: String {
case GET = "GET"
case POST = "POST"
}
我有一个请求类和一个请求包装类:
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
}
}
我在行上设置了条件断点:
return request.method.rawValue == incomingRequest.HTTPMethod
有条件:
self.request.method == HTTPMethod.POST
然后调试器停在错误信息行:
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: use of unresolved identifier 'self'
self.request.HTTPMethod == HTTPMethod.POST
如果我删除 self 并将条件更改为:
request.method == HTTPMethod.POST
错误信息如下:
Stopped due to an error evaluating condition of breakpoint 1.1:
"request.method == HTTPMethod.POST"
Couldn't parse conditional expression:
<EXPR>:1:1: error: could not find member 'method'
request.method == HTTPMethod.POST
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
有没有办法解决这个问题?
更新:
可以使用 LLDB 命令检查self.request.method 的值:
fr v self.request.method
如果我使用本地常量来存储值,调试器可以在正确的位置停止:
// Use a local constant to store the HTTP method
let method = request.method
// Condition of breakpoint
method == HTTPMethod.POST
更新 2:
我使用的是 Xcode 6.3.1
【问题讨论】:
标签: ios swift debugging enums lldb