相关疑难解决方法(0)

如何正确处理带参数的Swift块中的弱自我

在我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)

ios retain-cycle swift

143
推荐指数
7
解决办法
11万
查看次数

在 swift 中,函数可以是类型吗?

在通过按 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)

generics xcode function ios swift

0
推荐指数
1
解决办法
4158
查看次数

标签 统计

ios ×2

swift ×2

function ×1

generics ×1

retain-cycle ×1

xcode ×1