- iOS (Swift)gdtouhaozhoupu.cn
Swift 是一种用于 iOS 和 macOS 开发的编程语言。
swift
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
let label = UILabel()
label.text = "Hello, World!"
label.frame = CGRect(x: 50, y: 100, width: 200, height: 50)
self.view.addSubview(label)
}
}
2. Android (Java)
Java 是 Android 开发的主要语言之一。
java
import android.os.Bundle;
import android.app.Activity;
import android.widget.TextView;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView textView = new TextView(this);
textView.setTextSize(20);
textView.setText(“Hello, World!”);
setContentView(textView);
}
}
3. Web (React.js)
React.js 是一个用于构建用户界面的 JavaScript 库。
jsx
import React from ‘react’;
import ReactDOM from ‘react-dom’;
function App() {
return (
Hello, World!
);
}
ReactDOM.render(, document.getElementById(‘root’));
4. 后端 (Node.js with Express)
Node.js 是一个基于 Chrome V8 引擎的 JavaScript 运行环境,而 Express 是一个流行的 Node.js 框架。
javascript
const express = require(‘express’);
const app = express();
const port = 3000;
app.get(‘/’, (req, res) => {
res.send(‘Hello, World!’);
});
app.listen(port, () => {
console.log(App listening at http://localhost:${port}
);
});
5. 数据库 (MongoDB)
MongoDB 是一个基于文档的 NoSQL 数据库。以下是一个简单的 MongoDB shell 命令来插入一个文档。
bash
use myDatabase
db.myCollection.insert({ name: “World”, message: “Hello, World!” })
请注意,这些只是非常基础的示例,用于展示不同语言和平台上的基本结构。开发一个完整的 app 通常需要更多的代码、配置和测试。由于一个完整的app代码通常涉及多个部分(如前端、后端、数据库等),并且不同的平台(如iOS、Android、Web等)使用不同的技术和语言,我将为你提供几种常见语言和平台上的简单示例代码片段。
- iOS (Swift)
Swift 是一种用于 iOS 和 macOS 开发的编程语言。
swift
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
let label = UILabel()
label.text = "Hello, World!"
label.frame = CGRect(x: 50, y: 100, width: 200, height: 50)
self.view.addSubview(label)
}
}
2. Android (Java)
Java 是 Android 开发的主要语言之一。
java
import android.os.Bundle;
import android.app.Activity;
import android.widget.TextView;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView textView = new TextView(this);
textView.setTextSize(20);
textView.setText(“Hello, World!”);
setContentView(textView);
}
}
3. Web (React.js)
React.js 是一个用于构建用户界面的 JavaScript 库。
jsx
import React from ‘react’;
import ReactDOM from ‘react-dom’;
function App() {
return (
Hello, World!
);
}
ReactDOM.render(, document.getElementById(‘root’));
4. 后端 (Node.js with Express)
Node.js 是一个基于 Chrome V8 引擎的 JavaScript 运行环境,而 Express 是一个流行的 Node.js 框架。
javascript
const express = require(‘express’);
const app = express();
const port = 3000;
app.get(‘/’, (req, res) => {
res.send(‘Hello, World!’);
});
app.listen(port, () => {
console.log(App listening at http://localhost:${port}
);
});
5. 数据库 (MongoDB)
MongoDB 是一个基于文档的 NoSQL 数据库。以下是一个简单的 MongoDB shell 命令来插入一个文档。
bash
use myDatabase
db.myCollection.insert({ name: “World”, message: “Hello, World!” })
请注意,这些只是非常基础的示例,用于展示不同语言和平台上的基本结构。开发一个完整的 app 通常需要更多的代码、配置和测试。**