由于信号分段故障11 Xcode 9-iOS模拟器,命令失败

由于信号分段故障11 Xcode 9-iOS模拟器,命令失败,ios,swift,segmentation-fault,ios-simulator,xcode9.3,Ios,Swift,Segmentation Fault,Ios Simulator,Xcode9.3,我的代码是用swift 4.1在Xcode 9.3上编译的, 我可以在设备上运行我的代码,但是当我尝试在模拟器上运行代码时,它会给我以下错误: 我尝试了很多解决这个错误的方法,但是没有一个对我有效 我的swift文件中有以下代码,导致此错误 import Foundation import UIKit extension UITableView { func register<T: UITableViewCell>(_: T.Type) where T: Reusable

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

我尝试了很多解决这个错误的方法,但是没有一个对我有效

我的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)
  }
}
<代码>导入基础 导入UIKit 扩展UITableView{ func寄存器(uu:T.Type),其中T:ReusableView,T:NibLoadableView{ self.register(T.nib,forCellReuseIdentifier:T.reuseIdentifier) } func registerClass(uuz:T.Type),其中T:ReusableView,T:NibLoadableView{ self.register(T.self,forCellReuseIdentifier:T.reuseIdentifier) } func dequeueReusableCell(forindexath:indexath)->T?其中T:ReusableView{ guard let cell=self.dequeueReuseAbleCell(标识符为:T.reuseIdentifier,for:indexPath)作为?T else{ fatalError(“无法将标识符为\(T.reuseIdentifier)的单元格出列”) } 返回单元 } } 扩展UICollectionView{ func寄存器(uux:T.Type),其中T:ReusableView{ self.register(T.self,forCellWithReuseIdentifier:T.reuseIdentifier) } //func寄存器(uUt:T.Type){ //self.register(T.nib,forCellWithReuseIdentifier:T.reuseIdentifier) // } func dequeueReusableCell(forindexath:indexath)->T?其中T:ReusableView{ guard let cell=self.dequeueReuseAbleCell(带reuseIdentifier:T.reuseIdentifier,for:indexPath)作为?T else{ fatalError(“无法将标识符为\(T.reuseIdentifier)的单元格出列”) } 返回单元 } } //标记:使用autoresizingMask(FlexibleWidth和FlexibleHeight)添加到superView 扩展UIView{ func getKeyboardFrame(ukeyboardnotification:Notification)->CGRect{ guard let info=keyboardNotification.userInfo else{return CGRect(x:0,y:0,width:0,height:0)} 将值:AnyObject=info[UIKeyboardFrameEndUserInfoKey]设为AnyObject 让rawFrame=value.cgRectValue 返回self.convert(rawFrame!,from:nil) } //MARK:从Nib获取UIView 类func getNibView()->T?其中T:NibLoadableView{ 返回Bundle.main.loadNibNamed(T.nibName,所有者:self,选项:nil)?[0]作为?T } ///向超级视图中添加一个视图,该视图的边框等于超级视图的边界,并且该视图启用了自动调整大小遮罩。 func添加(到superView:UIView){ self.frame=superView.bounds self.autoresizingMask=[ .可弯曲宽度, .灵活高度 ] superView.addSubview(自) } } 此代码在编译时有一些警告


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

我认为这是真正的编译器问题。尝试做一些小的改变,直到它起作用

是的,我认为你是对的。在多次构建错误之后,我能够在模拟器上运行代码。没有任何更改。代码最初是用swift 2.2编写的,我正在升级为用swift 4编译