第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

代表們在斯威夫特?

代表們在斯威夫特?

收到一只叮咚 2019-06-24 15:45:05
代表們在斯威夫特?一個人如何去做一個代表?NSUserNotificationCenterDelegate在斯威夫特?
查看完整描述

3 回答

?
慕仙森

TA貢獻1827條經(jīng)驗 獲得超8個贊

這和obj-c沒什么不同。首先,必須在類聲明中指定協(xié)議,如下所示:

class MyClass: NSUserNotificationCenterDelegate

實現(xiàn)如下:

// NSUserNotificationCenterDelegate implementationfunc userNotificationCenter(center: NSUserNotificationCenter, 
didDeliverNotification notification: NSUserNotification) {
    //implementation}func userNotificationCenter(center: NSUserNotificationCenter, didActivateNotification notification: 
    NSUserNotification) {
    //implementation}func userNotificationCenter(center: NSUserNotificationCenter, shouldPresentNotification notification: 
    NSUserNotification) -> Bool {
    //implementation    return true}

當然,您必須設(shè)置委托。例如:

NSUserNotificationCenter.defaultUserNotificationCenter().delegate = self;


查看完整回答
反對 回復 2019-06-24
?
慕標5832272

TA貢獻1966條經(jīng)驗 獲得超4個贊

代表們總是把我搞糊涂直到我意識到委托只是一個為另一個類做一些工作的類。..這就像有別人為你做所有你不想做的骯臟工作。

我寫了一個小故事來說明這一點。如果你愿意的話,可以在游樂場里讀一讀。

很久以前.。

// MARK: Background to the story// A protocol is like a list of rules that need to be followed.protocol OlderSiblingDelegate: class {
    // The following command (ie, method) must be obeyed by any 
    // underling (ie, delegate) of the older sibling.    func getYourNiceOlderSiblingAGlassOfWater()}
    // MARK: Characters in the storyclass BossyBigBrother {

    // I can make whichever little sibling is around at 
    // the time be my delegate (ie, slave)    weak var delegate: OlderSiblingDelegate?

    func tellSomebodyToGetMeSomeWater() {
        // The delegate is optional because even though 
        // I'm thirsty, there might not be anyone nearby 
        // that I can boss around.        delegate?.getYourNiceOlderSiblingAGlassOfWater()
    }}// Poor little sisters have to follow (or at least acknowledge) 
// their older sibling's rules (ie, protocol)class PoorLittleSister: OlderSiblingDelegate {

    func getYourNiceOlderSiblingAGlassOfWater() {
        // Little sis follows the letter of the law (ie, protocol),        // but no one said exactly how she had to respond.    
            print("Go get it yourself!")
    }}// MARK: The Story// Big bro is laying on the couch watching basketball on TV.let bigBro = BossyBigBrother()
    // He has a little sister named Sally.let sally = PoorLittleSister()// Sally walks into the room. How convenient! Now big bro 
// has someone there to boss around.bigBro.delegate = sally// So he tells her to get him some water.bigBro.tellSomebodyToGetMeSomeWater()
// Unfortunately no one lived happily ever after...// The end.

在評審中,編寫和使用委托模式有三個關(guān)鍵部分。

  1. 這個

    協(xié)議

    ,它定義了工人需要做的事情。
  2. 這個

    老板班

    它有一個委托變量,它用來告訴Worker類要做什么。
  3. 這個

    工人階級

    它采用了協(xié)議,并執(zhí)行了所需的操作。

現(xiàn)實生活

與以上我們的波西老大哥故事相比,代表們經(jīng)常被用于下列實際應用:

  1. 通訊

    一個類需要向另一個類發(fā)送一些信息。
  2. 定制化

    一個類希望允許另一個類自定義它。

最重要的是,這些類不需要事先了解彼此的任何信息,只需要委托類符合所需的協(xié)議。

我強烈建議閱讀以下兩篇文章。他們幫助我更好地理解了代表們文獻資料做。

再來一個音符

引用它們不擁有的其他類的委托應該使用weak關(guān)鍵字以避免強引用周期??匆?/trans>這個答案更多細節(jié)。


查看完整回答
反對 回復 2019-06-24
  • 3 回答
  • 0 關(guān)注
  • 529 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號