1. .frame(width: 200.0, height: 200.0) 控制默认窗体大小
2.去除Metal API Validation提示
Product->Scheme > Edit Scheme... > Run > Diagnostics > Metal API Validation.
3.本地安装git依赖资源(可能有的时候并不好用,显示不出自己的工程目录)
A 下载好github上的发布版,源码版不一样好用(请确认Swift包目录中包含Package.swift文件)
B Add Local...选中该目录
C 在项目目标(TARGETS)的Frameworks,Libraries and Embedded Content 标签中嵌入该包(有时修会不好用,可能还是跟GWF有关)
4.给xcode增加本地代理 , 安装Proxifier代理,注册机y9nhjy/Proxifier-Keygen: Proxifier注册机 (github.com)
前题你要有本地安装clash代理(这个就不详细说了)
打开Proxifier, 点击左上角的代理 新增加本地代理 127.0.0.1 端口7890 选中socket5
然后再进入xcode,就可以 正常使用github上的开源资源了
5. 推荐3个源
GitHub - SwiftyJSON/SwiftyJSON: The better way to deal with JSON data in Swift.The better way to deal with JSON data in Swift. Contribute to SwiftyJSON/SwiftyJSON development by creating an account on GitHub.https://github.com/SwiftyJSON/SwiftyJSON.git
GitHub - Moya/Moya: Network abstraction layer written in Swift.Network abstraction layer written in Swift. Contribute to Moya/Moya development by creating an account on GitHub.https://github.com/Moya/Moya.gitGitHub - alibaba/HandyJSON: A handy swift json-object serialization/deserialization libraryA handy swift json-object serialization/deserialization library - alibaba/HandyJSONhttps://github.com/alibaba/HandyJSON.git
6. 模拟登陆成功后,进入主页面:新建工程
新建AuthManager.swift
import Foundation
import SwiftUI
class AuthManager: ObservableObject {
@Published var isLoggedIn = false // 用户登录状态
func login() {
// 在这里执行登录逻辑,例如验证用户凭据
// 登录成功后将 isLoggedIn 设置为 true
isLoggedIn = true
}
}
新建view LoginView.swift
import SwiftUI
struct LoginView: View {
@ObservedObject var authManager: AuthManager
@State private var account: String = ""
@State private var password: String = ""
var body: some View {
VStack{
Form {
Section(header: Text("请登陆")) {
TextField("账号", text: $account)
TextField("密码", text: $password)
}.padding(10)
Section {
Button("登陆") {
authManager.isLoggedIn.toggle()
}
}
}
}
.frame(width: 200.0, height: 200.0)
}
}
struct LoginView_Previews: PreviewProvider {
static var previews: some View {
LoginView(authManager: AuthManager())
}
}
修改你的起动文件名.swift ,我的是test_11App
import SwiftUI
@main
struct test_11App: App {
@StateObject var authManager = AuthManager()
var body: some Scene {
WindowGroup {
if authManager.isLoggedIn{
ContentView()
}
else{
LoginView(authManager: authManager)
}
}
}
}
编译运行即可。