【问题标题】:Can i use ReactiveCocoa in swift 3?我可以在 swift 3 中使用 ReactiveCocoa 吗?
【发布时间】:2017-04-16 05:13:22
【问题描述】:

我必须在以下代码中使用 Reactive Cocoa 或 RxSwift 来实现动态标签高度和动态行高。

我可以在 Swift3 中使用 Reactive Cocoa 吗? ReactiveCocoa 和 RxSwift 有什么区别?

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell: BTSTableViewCell = self.tableView.dequeueReusableCell(withIdentifier: "BTSTableViewCellIdentifier")! as! BTSTableViewCell

    cell.configureWithPost(posts[indexPath.row])
    cell.delegate = self
    return cell

}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {

    // 259.5+ labelHeight+ bigImageHeight

    let postViewModel = posts[indexPath.row]

    //caption height
    var captionHeight = postViewModel.textDetail?.height(withConstrainedWidth: tableView.bounds.size.width - 20, font: UIFont.systemFont(ofSize: 17))

    captionHeight = ceil(captionHeight!)

    var finalCaptionHeight: CGFloat = 0.0;

    if postViewModel.showDetailedCaption {
        finalCaptionHeight = captionHeight!
    }
    else {
        finalCaptionHeight = min(41, captionHeight!)
    }
    return 259.5 + postViewModel.getBigImageHeightFor(tableView.bounds.size.width) + finalCaptionHeight

}

【问题讨论】:

  • @Peres 回答了您的问题,但我想知道,为什么您认为“必须使用 Reactive Cocoa 或 RxSwift [...] 来实现动态标签高度和动态行高”?
  • @Sebastian 实际上,我需要使用它,因为这是我的要求。

标签: ios swift3 reactive-cocoa rx-swift


【解决方案1】:

我可以在 Swift3 中使用 Reactive Cocoa 吗?

是的,你可以。该项目是located here。需要注意的是,ReactiveCocoa 将只有 UI 绑定,而实际的“引擎”称为 ReactiveSwift

ReactiveCocoa 和 RxSwift 有什么区别?

您可以找到比较here。但归根结底,两者都是两个非常强大的框架。无论您选择哪一个,您都不会弄错。

【讨论】:

  • 谢谢。你能帮我把上面的代码转换成 RxSwift 吗?
  • @Bharath 这超出了您的问题范围。请将此答案标记为已更正(如果您认为如此)并打开一个新问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多