gpt4 book ai didi

ios - 以编程方式剖析 iOS 协议(protocol),然后调用这些方法?

转载 作者:行者123 更新时间:2023-11-28 15:57:50 25 4
gpt4 key购买 nike

问题(反射(reflection)或类似问题?)

是否有可能(在 Swift 中)以编程方式提取 iOS 协议(protocol)的所有方法签名,例如 UITextViewDelegate,其方法都是可选的,而不必实例化一个单独的显式实现的类所有协议(protocol)的方法?

最佳答案

In this case, want to intervene as the delegate to intercept one of the methods and do some related operation to that activity, then daisy chain the delegate call forward. But unfortunately, becoming the delegate entails responsibility to forward all of the protocol the downstream consumer

如果你说的和我想的一样,实际上有一个非常简单的方法可以做到这一点:实现forwardingTarget(for:),就像我在这里做的那样:

https://github.com/mattneub/Programming-iOS-Book-Examples/blob/master/bk2ch12p611tabBarMore/ch25p882tabBarMore/MyDataSource.swift

想法是我不知道table view的dataSource到底是干什么的,因为table view和它的数据源都属于Cocoa,但是我想充当“man in the它们之间的“中间”,并在调用时调整一个数据源方法的行为。所有其他方法调用都被传递,我什至不知道它们是什么。

关于ios - 以编程方式剖析 iOS 协议(protocol),然后调用这些方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41475383/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com