🍏

GitHub Copilot for Xcode Chat使ってみた!

2025/02/17に公開

ついに来た!

xcodeで、「GitHub Copilot for Xcode Chat」が使えるようになりました🙌
今まで、CursorやVScodeを起動してプロンプト投げていたけど、やはりxcodeで書きたい!
でもAIとChatしながらがいい人にはありがたいです🥰

https://www.publickey1.jp/blog/25/github_copilot_chatxcodegithub_copilot_for_xcode_chat.html

https://github.com/github/CopilotForXcode

動画使い方紹介してます。やることはまずは、インストール済みの方はupdateして再起動しましょう!
まだインストールしてない人は、インストールしましょう!

https://youtu.be/Ssg2FlJgjoc

使ってみた感想。部分的な修正は必要ですが、ログイン画面を速攻で作ってくれた!
ありがたい💙❤️

ログイン画面ができたレイアウト気になるがいい感じだ。

LoginView.swift
import SwiftUI

struct LoginView: View {
    @State private var email: String = ""
    @State private var password: String = ""
    @State private var isSecure: Bool = true

    var body: some View {
        VStack(spacing: 20) {
            Text("Login")
                .font(.largeTitle)
                .fontWeight(.bold)
            
            TextField("Email", text: $email)
                .keyboardType(.emailAddress)
                .autocapitalization(.none)
                .padding()
                .background(Color(.secondarySystemBackground))
                .cornerRadius(10)
            
            HStack {
                if isSecure {
                    SecureField("Password", text: $password)
                } else {
                    TextField("Password", text: $password)
                }
                Button(action: {
                    isSecure.toggle()
                }) {
                    Image(systemName: isSecure ? "eye.slash" : "eye")
                        .foregroundColor(.gray)
                }
            }
            .padding()
            .background(Color(.secondarySystemBackground))
            .cornerRadius(10)
            
            Button(action: {
                // Handle login action
            }) {
                Text("Login")
                    .font(.headline)
                    .foregroundColor(.white)
                    .padding()
                    .frame(maxWidth: .infinity)
                    .background(Color.blue)
                    .cornerRadius(10)
            }
            
            Spacer()
        }
        .padding()
    }
}

#Preview {
    LoginView()
}

Todoリストも作ってくれたいいね。好みのUIではないかもしれないが、学習には最適なコードを書いてくれるのではないか?

MemoListView.swift
import SwiftUI

struct Memo: Identifiable {
    let id = UUID()
    var content: String
}

struct MemoListView: View {
    @State private var memos: [Memo] = [
        Memo(content: "First memo"),
        Memo(content: "Second memo"),
        Memo(content: "Third memo")
    ]
    @State private var newMemoContent: String = ""

    var body: some View {
        NavigationView {
            VStack {
                HStack {
                    TextField("New memo", text: $newMemoContent)
                        .textFieldStyle(RoundedBorderTextFieldStyle())
                        .padding()

                    Button(action: addMemo) {
                        Text("Add")
                            .padding()
                            .background(Color.blue)
                            .foregroundColor(.white)
                            .cornerRadius(8)
                    }
                }

                List {
                    ForEach(memos) { memo in
                        Text(memo.content)
                    }
                    .onDelete(perform: deleteMemo)
                }
            }
            .navigationTitle("Memos")
        }
    }

    private func addMemo() {
        guard !newMemoContent.isEmpty else { return }
        let newMemo = Memo(content: newMemoContent)
        memos.append(newMemo)
        newMemoContent = ""
    }

    private func deleteMemo(at offsets: IndexSet) {
        memos.remove(atOffsets: offsets)
    }
}

#Preview {
    MemoListView()
}

最後に

AI時代になると、xcodeもアシスト機能以外にChat機能も搭載されました。いやー便利だ。これから二限の仕事が楽になる時代が来るのだろうか???

まあ飛行機を操縦する操縦士のサポートをする副操縦士の役割をするだけなのだろうから、操縦するコードを書く人が下手くそだと自己起こしそうだから学習をして技術の向上は必要ですね😅
今後活用していこう。

好きなxcodeを使いこなしたい🍎🍏

Discussion