我写了一个习惯UIView,我发现了一个奇怪的问题.我认为这与一个非常基本的概念有关,但我只是不理解它,感叹.....
class ArrowView: UIView {
override func draw(_ rect: CGRect) {
let arrowPath = UIBezierPath.bezierPathWithArrowFromPoint(startPoint: CGPoint(x:bounds.size.width/2,y:bounds.size.height/3), endPoint: CGPoint(x:bounds.size.width/2, y:bounds.size.height/3*2), tailWidth: 8, headWidth: 24, headLength: 18)
let fillColor = UIColor(red: 0.00, green: 0.59, blue: 1.0, alpha: 1.0)
fillColor.setFill()
arrowPath.fill()
}
}
Run Code Online (Sandbox Code Playgroud)
这段代码工作正常,但如果我从覆盖绘制函数中抓取这一行,它就不会编译.错误说我不能使用bounds属性.
let arrowPath = UIBezierPath.bezierPathWithArrowFromPoint(startPoint: CGPoint(x:bounds.size.width/2,y:bounds.size.height/3), endPoint: CGPoint(x:bounds.size.width/2, y:bounds.size.height/3*2), tailWidth: 8, headWidth: 24, headLength: 18)
Run Code Online (Sandbox Code Playgroud)
不能在属性初始值设定项中使用实例成员'bounds'; 属性初始化程序在'self'可用之前运行
我不明白为什么我不能在func draw中使用这个界限
我遇到了以下问题,并想知道解决它的优雅方法是什么.假设我们有两个字符串:
string1 = "I love to eat $(fruit)"
string2 = "I love to eat apples"
Run Code Online (Sandbox Code Playgroud)
这些字符串之间的唯一区别是$(fruit)和apples.所以,我发现水果是苹果,dict{fruit:apples}可以归还.
另一个例子是:
string1 = "I have $(food1), $(food2), $(food3) for lunch"
string2 = "I have rice, soup, vegetables for lunch"
Run Code Online (Sandbox Code Playgroud)
我希望得到一个dict{food1:rice, food2:soup, food3:vegetables}结果.
任何人都对如何实现它有一个好主意?
编辑:
我想我需要功能更强大.
ex.
string1 = "I want to go to $(place)"
string2 = "I want to go to North America"
result: {place : North America}
ex.
string1 = "I won $(index)place in …Run Code Online (Sandbox Code Playgroud) 我有一些与 RISC V 手册相关的问题,它有不同类型的指令编码,如 R 型、I 型。就像 MIPS 编码一样。
* R-type
31 25 24 20 19 15 14 12 11 7 6 0
+------------+---------+---------+------+---------+-------------+
| funct7 | rs2 | rs1 |funct3| rd | opcode |
+------------+---------+---------+------+---------+-------------+
* I-type
31 20 19 15 14 12 11 7 6 0
+----------------------+---------+------+---------+-------------+
| imm | rs1 |funct3| rd | opcode |
+----------------------+---------+------+---------+-------------+
* S-type
31 25 24 20 19 15 14 12 11 7 6 0
+------------+---------+---------+------+---------+-------------+
| imm | rs2 | rs1 …Run Code Online (Sandbox Code Playgroud) 浏览 risc-v isa doc 后,它给我的印象是 riscv 支持 16 位(RVC)、32 位(RV32I)、64 位(RV64I)长度的指令。
对于 RV32I:立即数有符号扩展为 32 位
对于 RV64i:立即数有符号扩展为 64 位
RV32I 和 RV64I 似乎都使用 32 位指令大小,差异与符号扩展的大小有关。
我认为大指令大小允许您在指令中编码大量立即数,这应该比小指令大小更好,因为它很容易用完空间。
对于risc-v,RV64I,如果只使用32位指令长度,64位寄存器文件和内存地址,如何充分利用硬件资源。(例如,直接跳转到大内存地址。)
一般情况下,RV64I 的命名是否应该表示指令长度为 64 位?