- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我写了一个协议(protocol)和相应的扩展,它使用一个简单的 StringStack
与 "<origin>@<destination>"
形式的命名约定相结合在我的 Swift 应用程序中的嵌套 View 之间执行 segues。我是 swift 的新手,所以如果有更好的方法来实现跨多个 View 的前进和后退按钮,我愿意接受。但是,由于我在下面详述的原因,以下代码存在问题。
struct StringStack {
var stack: Array = [String]()
mutating func push(str: String)->Void {
self.stack.append(str)
}
mutating func pop()->String {
self.stack.popLast()
}
}
protocol SegueForwardAndBackward {
var thisIdentifier: String {get set}
var segueStack: StringStack {get set}
}
extension SegueForwardAndBackward where Self: UIViewController {
mutating func performForwardSegue(nextIdentifier: String) {
let identifier: String = thisIdentifier + "@" + nextIdentifier
segueStack.push(identifier)
performSegueWithIdentifier(identifier, sender: self)
}
mutating func performBackwardSegue() {
let divided = segueStack.pop().componentsSeparatedByString("@")
// reverses destination and origin of identifier
let segueIdentifier: String = divided[1] + "@" + divided[0]
performSegueWithIdentifier(segueIdentifier, sender: self)
}
func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if var destinationViewController: SegueForwardAndBackward = segue.destinationViewController as? SegueForwardAndBackward {
destinationViewController.segueStack = segueStack
}
}
}
我最初的问题是协议(protocol)扩展中不允许使用变异函数,详见 bug report .该报告中给出了一个建议的解决方法,但是以下导致错误声称 'SegueForwardAndBackward' is not a subtype of 'UIViewController'
.
class A: UIViewController, SegueForwardAndBackward {
mutating func testFunc() {
var p: SegueForwardAndBackward = self
p.performBackwardSegue()
}
}
我确实遇到了一个潜在的解决方案,我可以在其中制作 SegueForwardAndBackward
another question 中详述的类协议(protocol).但是,实现类协议(protocol)会导致段错误,我认为这是因为我将我的扩展声明为 where Self: UIViewController
。 ,不幸的是,我不知道如何解决这个问题。
目前,我对 Swift 中的另一个错误感到非常沮丧,因此,如果您能帮助我改进我的方法或破译这些错误,我们将不胜感激。
预先感谢您的回复!
最佳答案
这question似乎解决了嵌套前进和后退按钮的替代解决方案,因此在没有任何其他响应的情况下,这就是我要解决的问题。然而,我提出的问题仍然是 swift 中一个非常奇怪的错误。
关于swift - 协议(protocol)扩展中的变异函数,其中 Self 是 UIViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36489853/
我有一个包含配对数据的数据集(同一家庭的成员)。 身份证 是个人标识符和 户号是合作伙伴的标识符(反之亦然)。 我需要的是为每个 添加一个额外的列(职业)。 id 他\她的伴侣。 我的数据看起来像这样
mutate 能否根据跨变量应用的逻辑条件创建新变量? 更具体地说,请考虑以下数据。 set.seed(1234) val = 1) head(dat) a b c d anyABCD 1 0 0
我的 df 看起来像这样: df % mutate_at(vars(starts_with("paid")), list(prc = ~. / expenses)) # expenses mon
我的 df 看起来像这样: df % mutate_at(vars(starts_with("paid")), list(prc = ~. / expenses)) # expenses mon
我在这里为项目 Euler 问题 31 运行了这个简单的代码。 不需要 Euler Q;我只想知道,为什么我的列表值会发生变化,即这是打印 [2.0,2.0,2.0,2.0,2.0] 的许多列表的列表
我使用了排列和变异组合来根据分组进行添加。例如,我使用了以下内容: master_df % group_by(asof_dt) %>% mutate(tot_flag = sum(ls_fla
我在让 mutate、cross 和 case_when 正常运行时遇到了一些麻烦,我在这里重新创建了一个简单版本的问题: a 1 1 2 3 2 2
我有代表用户某种交易类型的不规则时间序列数据。每行数据都带有时间戳,表示当时的事务。由于数据的不规则性质,某些用户一天可能有100行,而其他用户一天可能有0或1个事务。 数据可能看起来像这样: dat
您如何恰本地解释为什么这两个示例不同? // Reassignment let a = 1; let b = a; a = 2; console.log(b); // → 1 // Mutation
基本上我想做的是发送一个字符串列表 ex: ["aa","bb","vv"] 到 graphql Mutation 字段中,目前这是我的 Mutation Schema "listTest": &gr
使用 dplyr 进行组均值居中的有效/首选方法是什么,即获取组中的每个元素(mutate)并对其执行操作和汇总统计信息(该组的总结)。以下是使用基本 R 以 mtcars 为中心的组均值: do.c
pcd % arrange(tripNo, procDate, delay) %>% group_by(tripNo) %>% mutate(delayErr = (row_number(
我想知道查询类型后面的字符串有什么意义,在这种情况下是“ProvisionQueues”,似乎从字符串中删除它不会影响任何东西——它只是用于日志记录还是什么。元数据? mutation Provisi
所以,我正在尝试设计我的 Apollo 服务器。我想用一个对象作为参数来创建一个突变。 这是我的架构的一个片段,它以某种方式导致了问题: 我认为它在语法上是正确的,但我遇到了这个错误: {"error
CREATE OR REPLACE TRIGGER UPDATE_TEST_280510 AFTER insert on TEST_TRNCOMPVISIT declare V_TRNCOMPNO N
我有以下带有查询和突变的组件,但我的组件没有收到数据和突变 prop。 我的代码是不是做错了什么或遗漏了什么?虽然查询确实得到执行,但它没有传递下去。 this.props.mutate 和 this
我用 Go 编写了一个客户端应用程序,它需要与服务器端的 C 程序进行交互。客户端执行 AES CFB 加密,服务器解密。不幸的是,服务器端存在重用初始化向量的错误。它尝试根据以下条件进行 3 次解密
我的前端是 localhost:3000 ,我的 GraphQL 服务器是 localhost:3333 . 我已经使用 react-apollo 在 JSX 领域中查询/变异,但还没有从 Expre
我试图改变通常情况下来自 kube-scheduler 的资源“绑定(bind)”。 以下是我的“ValidatingWebhookConfiguration”yaml: apiVersion: ad
如所述here , 这是一个 reference implementation用于 kubernetes e2e 测试的 webhook 服务器。在 main 函数中,定义了一些端点来处理不同的突变请
我是一名优秀的程序员,十分优秀!