Reputation: 1250
My code is compiling on Xcode 9.3 with swift 4.1, I'm able to run my code on the device, but while trying to run this code on the simulator, it gives me following error,
I tried so many solutions available for this error, but none of them had worked for me.
I have following code in my swift file, which is causing this error,
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)
}
}
This code has some warnings while compiling
I want to run code on the simulator, but not able to do that.
Upvotes: 0
Views: 486
Reputation: 2183
I think these are genuine compiler issues. Try to make smallish changes until it works.
Upvotes: 1