在我TextViewTableViewCell,我有一个变量来跟踪块和一个配置方法,其中传入和分配块.
这是我的TextViewTableViewCell班级:
//
// TextViewTableViewCell.swift
//
import UIKit
class TextViewTableViewCell: UITableViewCell, UITextViewDelegate {
@IBOutlet var textView : UITextView
var onTextViewEditClosure : ((text : String) -> Void)?
func configure(#text: String?, onTextEdit : ((text : String) -> Void)) {
onTextViewEditClosure = onTextEdit
textView.delegate = self
textView.text = text
}
// #pragma mark - Text View Delegate
func textViewDidEndEditing(textView: UITextView!) {
if onTextViewEditClosure {
onTextViewEditClosure!(text: textView.text)
}
}
}
Run Code Online (Sandbox Code Playgroud)
当我在我的cellForRowAtIndexPath方法中使用configure方法时,如何在我传入的块中正确使用弱自我.
这是我没有弱自我的情况:
let myCell = tableView.dequeueReusableCellWithIdentifier(textViewCellIdenfitier) as TextViewTableViewCell …Run Code Online (Sandbox Code Playgroud) 在通过按 command+click 研究 XCTAssert 方法时,看起来它们的底层方法是一个具有类型的函数(称为 T 的通用类型,符合 Equatable 协议)。我说得对吗?如果是的话,函数如何遵守协议?函数是类型吗?
public func XCTAssertEqual<T : Equatable>(_ expression1: @autoclosure () throws -> ArraySlice<T>, _ expression2: @autoclosure () throws -> ArraySlice<T>, _ message: @autoclosure () -> String = default, file: StaticString = #file, line: UInt = #line)
Run Code Online (Sandbox Code Playgroud)
这行是最令人困惑的,我在上面试图解释:
func XCTAssertEqual<T : Equatable>`
Run Code Online (Sandbox Code Playgroud)