Results 107 issues of Hui

main.swift ```swift import SwiftUI print("#1") DispatchQueue.main.async { print("#2") } print("#3") print(Thread.current) RunLoop.main.run() ``` Output: ```sh # 1 # 3 #3 {number = 1, name = main} # 2 ``` 这个sample中主要涉及三个概念:...

app.swift ```swift import SwiftUI struct MyApp: App { var body: some Scene { WindowGroup { Text("Hello, world!") .frame(width: 300, height: 300) } } } MyApp.main() ``` - 同目录下直接`swiftc -o app...

## Packaging swift的hello world都是从hello.swift开始, ```swift print("hello world") ``` 无需编译直接运行: ```sh ~ swift hello.swift hello world ``` 那我们现在再创建一个foo.swift ```swift func hello() { print("hello world") } ``` 同时,将hello.swift改为调用, ```swift hello() ``` 这时候问题就来了,...

## Snippets 1 ```swift struct User { var name: String? } let user = User(name: "nonocast") print(user.name!) ``` - let和var的区别: ```sh 12> var foo = 1 foo: Int = 1...

Swift的project结构和package manager的形式总体上来说了javascript相似,npm/yarn init类似swift init, 然后swift package manger (Swift PM)类似npm repo。又因为Swift是强类型语言,所以swift/swiftc和java/javac是一个意思。 (更新: 此处描述有错误,请参考 #246) ## swift and swiftc - swift: swift is an interactive environment (REPL) for Swift. - swiftc: swift...

## Cocoa 官方文档: [What Is Cocoa?](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/CocoaFundamentals/WhatIsCocoa/WhatIsCocoa.html) > Cocoa is an application environment for both the OS X operating system and iOS, the operating system used on Multi-Touch devices such as...

## 快捷键 - Build: command+B - Clean: command+shift+K - Format: command+A, ctrl+I - Library: command+shift+L ## 第一个SwiftUI布局 ```swift import SwiftUI struct ContentView: View { var body: some View { VStack(alignment:...

# C语言基础 gcc从app.c到a.out分为4个步骤: - Prepressing (预处理) - Compilation (编译) - Assembly (汇编) - Linking (链接) Prepressing (预编译) ------------------- $gcc -E app.c -o app.i gcc实际是一个工具链,针对不同的语言有不同的套路,如果是c语言则采用cpp来做真正的预编译,所以效果等同于调用, $cpp hello.c > hello.i 假定app.c ```c...

意图: 创建一个程序每5秒从unsplash上更新一张图片。 创建一个Storyboard Swift的App,然后在XIB上放上一个ImageView, 正确设置AutoResizing,确保图片全尺寸,然后将outlets拖入ViewController.swift。 ```swift import Cocoa class ViewController: NSViewController { @IBOutlet weak var imageView: NSImageView! var timer: Timer? override func viewDidLoad() { super.viewDidLoad() self.imageView.image = NSImage(named:"sample") } override...

新建一个interface为XIB的Swift App,此时Xcode给出的template中关键的代码仅2个文件: - AppDelegate.swift ```swift import Cocoa @main class AppDelegate: NSObject, NSApplicationDelegate { @IBOutlet var window: NSWindow! func applicationDidFinishLaunching(_ aNotification: Notification) { // Insert code here to initialize your application...