UICollectionReusableView – 缺less函数返回
考虑到UICollectionView
的头部,我有一个奇怪的问题。
我基本上使用的代码: http : //www.raywenderlich.com/78551/beginning-ios-collection-views-swift-part-2
func collectionView(collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionReusableView { let dateFormatter = NSDateFormatter() dateFormatter.dateFormat = "dd.MM.yyyy' - 'HH:mm'" //1 switch kind { //2 case UICollectionElementKindSectionHeader: //3 let h = collectionView.dequeueReusableSupplementaryViewOfKind(kind, withReuseIdentifier: "eventHeaderView", forIndexPath: indexPath) as eventHeader h.eventFirstline.text = "First Line" h.eventSecondline.text = thisEvent.eventName h.eventDate.text = dateFormatter.stringFromDate(thisEvent.startDate) h.eventDescription.text = thisEvent.shortDescription return h default: //4 assert(false, "Unexpected element kind") } }
所有这些在即时部署到模拟器或真实设备时都可以很好地工作,但奇怪的是,当我想为testing目的构buildAd-Hoc包时,它告诉我
缺less返回的函数预期返回'UICollectionReusableView'
那么好吧,switch-case之外什么也没有,所以它什么都不能返回 – 但是为什么只有在我试图构build一个包的时候才会给出“热部署”的警告呢?
assert()
仅在Debugconfiguration中评估。 当你build立一个档案时,代码被编译成发布configuration(带有优化),条件被简单地忽略(假定为true
)。 因此编译器会抱怨缺less的返回值。
您可以使用
fatalError("Unexpected element kind")
代替。 fatalError()
总是被评估,另外用@noreturn
标记(在Swift 3中Never
返回types),以便编译器知道它不会返回给它的调用者。
另请参阅Swift – 带开关语句的fatalError 。
- UIButton子类@IBAction不工作
- 实际上使用UIDatePickerModeCountDownTimer作为一个计时器
- 为什么我的iOS应用程序不能在其他应用程序的“打开”对话框中显示?
- 更改SLComposeServiceViewController上的button标题?
- 把CLLocationCoordinate2D放到Swift的CLLocation中
- Swift中的错误:属性'self.circle1'在super.init调用时未初始化?
- 从nsarray中获得n个随机对象(例如4个)
- 有没有什么办法像“提高说话”function一样来监控用户的iPhone动作?
- 缩进UITextField中的文本