swift - Fail to imply _Reflectable protocol -


i reading mirrortype @ nshipster,and trying adopt it's code swift 2.1. works fine until when tried custom _mirrortypewith :

extension wwdcsession : _reflectable {     func _getmirror() -> _mirrortype {        return wwdcsessionmirror(self)     } } 

an error occured :

error: playground execution aborted: execution interrupted, reason: exc_bad_access (code=2, address=0x7fff58273e87).

and found out it's because init method in wwdcsessionmirror being called infinite times.

struct wwdcsessionmirror: _mirrortype { private let _value: wwdcsession  init(_ value: wwdcsession) {     _value = value }  var value: { return _value }  var valuetype: any.type { return wwdcsession.self }  var objectidentifier: objectidentifier? { return nil }  var disposition: _mirrordisposition { return .struct }  var count: int { return 4 }  subscript(index: int) -> (string, _mirrortype) {     switch index {     case 0:         return ("number", _reflect(_value.number))     case 1:         return ("title", _reflect(_value.title))     case 2:         return ("track", _reflect(_value.track))     case 3:         return ("summary", _reflect(_value.summary))     default:         fatalerror("index out of range")     } }  var summary: string {     return "wwdcsession \(_value.number) [\(_value.track.rawvalue)]: \(_value.title)" }  var quicklookobject: playgroundquicklook? {     print(summary)     return .text(summary) } } 

i want ask why happened , , how fix it?

_reflectable , _mirrortype not droids you're looking for.

they legacy types, have been superseded customreflectable (among others). 2015 wwdc session lldb goes detail (disclaimer: speaker of part of session, conflict of interests around :-)

but, anyway, issue you're running because of line:

_value = value 

since you're typing line in playground, tells playground logic capture display ("log" in playground parlance) thing you're assigning. so, playground uses mirror attached type. so, go off , create one, causes run

_value = value 

again, tells playground logic log value, means create mirror, ...

you should first of check if can adopt mirror , customreflectable instead of _mirrortype , if using apis fixes problem. if doesn't possible workaround put reflection support code in auxiliary source file cause playground logic not log things inside of it.


Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -