我一直在关注教程并遇到以下代码片段:
const myAsyncFunction = async () => {
const usersResponse = await fetch(
'https://jsonplaceholder.typicode.com/users'
)
const userJson = await usersResponse.json();
const secondUser = userJson[1];
console.log(secondUser);
const posts = await fetch (
'https://jsonplaceholder.typicode.com/posts?userId=' + secondUser.id
);
const postsJson = await posts.json();
console.log(postsJson);
}
myAsyncFunction();
Run Code Online (Sandbox Code Playgroud)
是否应该立即将响应转换为 JSON 对象,就像从数组中获取值userJson[1]一样?为什么需要await usersResponse.json()和posts.json()?
所以,我有一个关于 Swift 中的类和函数的相当简单的问题。
假设我用 SpriteKit 制作了一个应用程序。我有一个 GameScene (SKScene)、一个 GameViewController (UIViewController) 和一个用于 GameViewController 的主故事板。
如果我想在我的 GameScene 顶部有一个按钮,我会将一个按钮 IBOutlet 从主故事板连接到 GameViewController。但是我如何设置它,以便在我触摸按钮时可以调用 GameScene 中的函数?
我必须通过委托来处理这个问题还是有更简单的方法?
编辑:
详细说明,我想调用的函数是:
func resetScene(){
self.removeAllActions()
self.removeAllChildren()
}
Run Code Online (Sandbox Code Playgroud)
我试图声明为 aclass func但不知何故它不太工作。
尝试用 homebrew 更新我的 git,我遇到了这个问题:
MBP:GitHub_Tutorial nasdas$ brew install git
Warning: git 2.21.0 is already installed and up-to-date
To reinstall 2.21.0, run `brew reinstall git`
MBP:GitHub_Tutorial nasdas$ git --version
git version 2.17.2 (Apple Git-113)
Run Code Online (Sandbox Code Playgroud) 我知道创建抽象类背后的概念用法,即为其子类定义一个公共接口,其中一些实现留给各个子类.
我是否正确地假设技术上没有必要抽象类,因为你可以覆盖超类方法?是否创建了抽象类以使类的意图更清晰?
我的意思是:
// Using an abstract class
abstract class Car
{
int fuel;
int getFuel()
{
return this.fuel;
}
abstract String getColor();
}
class RedCar extends Car
{
String getColor()
{
return "red";
}
}
// Without an abstract class
class Car
{
int fuel;
int getFuel()
{
return this.fuel;
}
String getColor()
{
return "defaultColor";
}
class RedCar extends Car
{
String getColor()
{
return "red";
}
}
Run Code Online (Sandbox Code Playgroud) class ×2
async-await ×1
asynchronous ×1
function ×1
git ×1
homebrew ×1
ios ×1
java ×1
javascript ×1
object ×1
oop ×1
promise ×1
sprite-kit ×1
swift ×1
terminal ×1