我有一个指向类功能之一的类属性。但是,当我尝试使用函数之一初始化此变量时,出现以下错误:
在初始化所有存储的属性之前,在方法调用中使用“ self”。
我可以为这些函数初始化任何其他变量,但是即使没有,该错误也听起来像我在调用该函数。
import UIKit
import AudioToolbox
class BeatMaker {
// iPhone 7 and up use beat function, iPhone 6s use beatFallback
let hapticFunction: () -> ()
let impactGenerator = UIImpactFeedbackGenerator.init(style: .heavy)
init(supportsImpactGenerator: Bool) {
// error 1: 'self' used in method call 'beat' before all stored properties are initialized
// error 2: 'self' used in method call 'beatFallback' before all stored properties are initialized
self.hapticFunction = (supportsImpactGenerator) ? beat : beatFallback
}
private func beat() {
impactGenerator.impactOccurred()
} …
Run Code Online (Sandbox Code Playgroud) 我尝试创建一个函数然后立即调用它。
function(x){x+1}(3)
Run Code Online (Sandbox Code Playgroud)
这会产生一些奇怪的结果。幸运的是,我已经知道我错在哪里了。我应该在尝试调用函数语句之前先对其进行求值。
(function(x){x+1})(3)
# 4
Run Code Online (Sandbox Code Playgroud)
但是,我对第一行代码的实际计算结果感到困惑。有人能解释一下下面的 R 代码中发生了什么吗?
a <- function(x){x+1}(3)
a
# function(x){x+1}(3)
class(a)
# [1] "function"
a(3)
# Error in a(3) : attempt to apply non-function
a()
# Error in a() : argument "x" is missing, with no default
(a)
# function(x){x+1}(3)
# <bytecode: 0x128b52c50>
# everything in brackets on the right don't seem to be evaluated
function(x){x+1}(1)(2)(a,b,c)[1:4,d:5,,,][seq_along(letters)]
# function(x){x+1}(1)(2)(a,b,c)[1:4,d:5,,,][seq_along(letters)]
(function(x){x+1}(1)(2)(a,b,c)[1:4,d:5,,,][seq_along(letters)])
# function(x){x+1}(1)(2)(a,b,c)[1:4,d:5,,,][seq_along(letters)]
((function(x){x+1}(1)(2)(a,b,c)[1:4,d:5,,,][seq_along(letters)]))
# function(x){x+1}(1)(2)(a,b,c)[1:4,d:5,,,][seq_along(letters)]
Run Code Online (Sandbox Code Playgroud) 我从头开始在 XCode 中构建了一个 Safari 扩展。主要目标是在观看某些内容时隐藏 YouTube 上的视频推荐 - 我想我可以使用一些 css 属性来做到这一点。
\n\n出于测试目的,我添加了一些更多的样式修改。
\n\n/* Testing */\nbody {\n background: red !important;\n color: blue !important;\n}\n\n/* Hide column with video recommendations */\n#secondary {\n display: none !important;\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n由于某种原因,我保存在 nostyle.css 中的这些 css 属性不会影响站点。
\n\n我尽可能严格地遵循有关注入 CSS 样式表的Apple 指南,主要是通过编辑 Info.plist 文件:
\n\nStyle Sheet
(注意空格)和值nostyle.css
(与项目默认设置一起提供的与“script.js”位于同一目录中的文件)*.youtube.com
到允许的域列表中(以及用于测试目的的其他 URL)我使用 script.js 文件在控制台中输出消息,尽管速度有些不一致。
\n\n我没有碰过任何其他文件(除了我添加了一些图标Assets.xcassets
)。下面显示了 …
我想通过遍历从特定行号开始的行来从 Pandas 数据框中读取数据。我知道有df.iterrows()
,但它不允许我指定从哪里开始迭代。
在我的特定情况下,我有一个 csv 文件,它可能如下所示:
Date, Temperature
21/08/2017 17:00:00,5.53
21/08/2017 18:00:00,5.58
21/08/2017 19:00:00,4.80
21/08/2017 20:00:00,4.59
21/08/2017 21:00:00,3.72
21/08/2017 22:00:00,3.95
21/08/2017 23:00:00,3.11
22/08/2017 00:00:00,3.07
22/08/2017 01:00:00,2.80
22/08/2017 02:00:00,2.75
22/08/2017 03:00:00,2.79
22/08/2017 04:00:00,2.76
22/08/2017 05:00:00,2.76
22/08/2017 06:00:00,3.06
22/08/2017 07:00:00,3.88
Run Code Online (Sandbox Code Playgroud)
我想从特定时间点(假设是 8 月 22 日午夜)开始遍历每一行,所以我尝试像这样实现它:
Date, Temperature
21/08/2017 17:00:00,5.53
21/08/2017 18:00:00,5.58
21/08/2017 19:00:00,4.80
21/08/2017 20:00:00,4.59
21/08/2017 21:00:00,3.72
21/08/2017 22:00:00,3.95
21/08/2017 23:00:00,3.11
22/08/2017 00:00:00,3.07
22/08/2017 01:00:00,2.80
22/08/2017 02:00:00,2.75
22/08/2017 03:00:00,2.79
22/08/2017 04:00:00,2.76
22/08/2017 05:00:00,2.76
22/08/2017 06:00:00,3.06
22/08/2017 07:00:00,3.88
Run Code Online (Sandbox Code Playgroud)
result[0]
实际上给了我正确的数字。
我想我可以做的只是增加该数字并通过 …