【问题标题】:command failed due to signal segmentation fault 11 Xcode 9 - iOS simulator由于信号分段错误,命令失败 11 Xcode 9 - iOS 模拟器
【发布时间】:2018-06-05 13:10:12
【问题描述】:

我的代码在 Xcode 9.3 和 swift 4.1 上编译, 我可以在设备上运行我的代码,但是在尝试在模拟器上运行此代码时,它给了我以下错误,

我为这个错误尝试了很多可用的解决方案,但没有一个对我有用。

我的 swift 文件中有以下代码,导致此错误,

import Foundation
import UIKit


extension UITableView {

  func register<T: UITableViewCell>(_: T.Type) where T: ReusableView, T: NibLoadableView {
    self.register(T.nib, forCellReuseIdentifier: T.reuseIdentifier)
  }

  func registerClass<T: UITableViewCell>(_: T.Type) where T: ReusableView, T: NibLoadableView {
    self.register(T.self, forCellReuseIdentifier: T.reuseIdentifier)
  }

  func dequeueReusableCell<T: UITableViewCell>(forIndexPath indexPath: IndexPath) -> T? where T: ReusableView {
    guard let cell = self.dequeueReusableCell(withIdentifier: T.reuseIdentifier, for: indexPath) as? T else {
      fatalError("Could not dequeue cell with identifier: \(T.reuseIdentifier)")
    }
    return cell
  }

}


extension UICollectionView {

  func register<T: UICollectionViewCell>(_: T.Type) where T: ReusableView {
    self.register(T.self, forCellWithReuseIdentifier: T.reuseIdentifier)
  }

//  func register<T: UICollectionViewCell where T: ReusableView, T: NibLoadableView>(_: T.Type) {
//    self.register(T.nib, forCellWithReuseIdentifier: T.reuseIdentifier)
//  }

  func dequeueReusableCell<T: UICollectionViewCell>(forIndexPath indexPath: IndexPath) -> T? where T: ReusableView {
    guard let cell = self.dequeueReusableCell(withReuseIdentifier: T.reuseIdentifier, for: indexPath) as? T else {
      fatalError("Could not dequeue cell with identifier: \(T.reuseIdentifier)")
    }

    return cell
  }

}

// MARK: Add to superView with autoresizingMask(FlexibleWidth and FlexibleHeight)
extension UIView {

  func getKeyboardFrame(_ keyboardNotification: Notification) -> CGRect {
    guard let info  = keyboardNotification.userInfo else { return CGRect(x: 0, y: 0, width: 0, height: 0) }
    let value: AnyObject = info[UIKeyboardFrameEndUserInfoKey] as AnyObject

    let rawFrame = value.cgRectValue
    return self.convert(rawFrame!, from: nil)
  }

  // MARK: Get UIView from Nib
  class func getNibView<T: UIView>() -> T? where T: NibLoadableView {
    return Bundle.main.loadNibNamed(T.nibName, owner: self, options: nil)?[0] as? T
  }
  /// Add a view to a superview with the view's frame equal to the superview's bounds and the view having autoresizing mask enabled.
  func add(to superView: UIView) {
    self.frame = superView.bounds
    self.autoresizingMask = [
      .flexibleWidth,
      .flexibleHeight
    ]
    superView.addSubview(self)
  }
}

此代码在编译时有一些警告

我想在模拟器上运行代码,但无法做到。

【问题讨论】:

  • 代码最初是用swift 2.2编写的,我正在升级它以在swift 4中编译

标签: ios swift segmentation-fault ios-simulator xcode9.3


【解决方案1】:

我认为这些是真正的编译器问题。尝试进行微小的更改,直到它起作用。

【讨论】:

  • 是的,我认为你是对的。经过多次构建错误后,我能够在模拟器上运行代码。没有任何变化。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-12-20
  • 2015-12-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-12-18
相关资源
最近更新 更多