Crash in _KVOKeyPathBridgeMachinery should I file a JIRA?

Hi everyone,

I have found a crash in my app, I reduce it and make it works in the playground.
Should I file a Radar or a JIRA for this? When I try to observe a variable in a class that is public and that inherit from NSObject I have an assertion.

import Foundation

public class Manager {

  public class ExpectedVariable : NSObject {
    public var aBool : Bool = false
  }

  public enum Variable {
    case aBool(Bool)
  }

  var validResult : ExpectedVariable = ExpectedVariable()
  private var observers: [NSKeyValueObservation] = []

  public static func async(completion: @escaping (_ variable : Variable)->()) {
    Manager.shared.async(completion: completion)
  }

  public static let shared = Manager()
  private init() { }

  private func async(completion: @escaping (_ variable : Variable)->()) {
    observers.append(self.validResult.observe(\ExpectedVariable.aBool) { [weak self] a,b in
      guard let val = self?.validResult.aBool else { return }
      completion(.aBool(val))
    })
  }
}

Manager.async { (variable) in
  print(variable)
}

**Fatal error: Could not extract a String from KeyPath Swift.ReferenceWritableKeyPath<__lldb_expr_5.Manager.ExpectedVariable, Swift.Bool>: file /BuildRoot/Library/Caches/com.apple.xbs/Sources/swiftlang_Fall2018/swiftlang_Fall2018-1000.11.42/src/swift/stdlib/public/SDK/Foundation/NSObject.swift, line 85**
**Playground execution failed:**
**error: Execution was interrupted, reason: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0).**
**The process has been left at the point where it was interrupted, use "thread return -x" to return to the state before expression evaluation.**
*** thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)**
*** frame #0: 0x0000000119de7070 libswiftCore.dylib`function signature specialization <Arg[1] = Exploded> of Swift._assertionFailure(_: Swift.StaticString, _: Swift.String, file: Swift.StaticString, line: Swift.UInt, flags: Swift.UInt32) -> Swift.Never + 144**
**frame #1: 0x0000000119c1ae09 libswiftCore.dylib`Swift._assertionFailure(_: Swift.StaticString, _: Swift.String, file: Swift.StaticString, line: Swift.UInt, flags: Swift.UInt32) -> Swift.Never + 25**
**frame #2: 0x000000011a6582ee libswiftFoundation.dylib`function signature specialization <Arg[1] = Dead> of static Foundation.(_KVOKeyPathBridgeMachinery in _6DA0945A07226B3278459E9368612FF4)._bridgeKeyPath(Swift.AnyKeyPath) -> Swift.String + 526**
**frame #3: 0x000000011a5cefd8 libswiftFoundation.dylib`(extension in Foundation):Foundation._KeyValueCodingAndObserving.observe<A>(_: Swift.KeyPath<A, A1>, options: __C.NSKeyValueObservingOptions, changeHandler: (A, Foundation.NSKeyValueObservedChange<A1>) -> ()) -> Foundation.NSKeyValueObservation + 312**
**frame #4: 0x000000011cf728e4 $__lldb_expr6`Manager.async(completion=0x000000011cf72f60 $__lldb_expr6`closure #1 (__lldb_expr_5.Manager.Variable) -> () in __lldb_expr_5 at Bienvenue.xcplaygroundpage:59, self=0x00006000022e8260) at Bienvenue.xcplaygroundpage:51**
**frame #5: 0x000000011cf72427 $__lldb_expr6`static Manager.async(completion=0x000000011cf72f60 $__lldb_expr6`closure #1 (__lldb_expr_5.Manager.Variable) -> () in __lldb_expr_5 at Bienvenue.xcplaygroundpage:59, self=Manager) at Bienvenue.xcplaygroundpage:43**
**frame #6: 0x000000011cf71048 $__lldb_expr6`main at Bienvenue.xcplaygroundpage:59**
**frame #7: 0x00000001040d15f0 Screens`linkResources + 304**
**frame #8: 0x000000010594b62c CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12**
**frame #9: 0x000000010594ade0 CoreFoundation`__CFRunLoopDoBlocks + 336**
**frame #10: 0x0000000105945654 CoreFoundation`__CFRunLoopRun + 1284**
**frame #11: 0x0000000105944e11 CoreFoundation`CFRunLoopRunSpecific + 625**
**frame #12: 0x000000010ad131dd GraphicsServices`GSEventRunModal + 62**
**frame #13: 0x000000010b81881d UIKitCore`UIApplicationMain + 140**
**frame #14: 0x00000001040d16bd Screens`main + 205**
**frame #15: 0x000000010736e575 libdyld.dylib`start + 1**

I have to add @objc on ExpectedVariable.aBool it should be great if we knew at compile time that we should add this.

Can we close this, please?

Terms of Service

Privacy Policy

Cookie Policy