Swift 4.1 problem. Xcode 9.3 error


Have a problem after updating from Swift 4.0 to 4.1.

Here is my code:

protocol NSManagedObjectDecodable: class, Decodable {
  init(with decoder: Decoder) throws
extension NSManagedObjectDecodable where Self: NSManagedObject {
  init(with decoder: Decoder) throws {
    guard let context = decoder.userInfo[.context] as? NSManagedObjectContext else {
      throw NSError(domain: "", code: 123, userInfo: nil)
    guard let entity = NSEntityDescription.entity(forEntityName: String(describing: Self.self), in: context) else {
      throw NSError(domain: "", code: 123, userInfo: nil)
    self.init(entity: entity, insertInto: context)


And I use It here:


  required convenience init(from decoder: Decoder) throws {
    try self.init(with: decoder)

    let container = try decoder.container(keyedBy: CodingKeys.self)
    self.id = try String(container.decode(Int.self, forKey: .id))
    self.phoneNumber = try container.decode(String.self, forKey: .phoneNumber)


In Swift 4.0 it was OK. But after update It’s not compiling with this error:

Command filed due to signal: Segmentation fault: 11


If i commented this line:

try self.init(with: decoder)


and replace with, for example, with this:

  self.init(entity: NSEntityDescription(coder: NSCoder())!, insertInto: nil)


and it will work! What the problem? Idk

Thank u!

Powered by WPeMatico


You may also like...

Comments are closed.