Skip to content

Instantly share code, notes, and snippets.

@wizard1066
Created January 15, 2023 19:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wizard1066/73b9cd9b42593d437735af8c992ad2de to your computer and use it in GitHub Desktop.
Save wizard1066/73b9cd9b42593d437735af8c992ad2de to your computer and use it in GitHub Desktop.
import SwiftUI
import MultipeerConnectivity
import Combine
let feedback = PassthroughSubject<CGPoint,Never>()
let screenSize: CGRect = UIScreen.main.bounds
let screenWidth: CGFloat = UIScreen.main.bounds.width
let screenHeight: CGFloat = UIScreen.main.bounds.height
struct Fonts {
static func avenirNextCondensedBold (size: CGFloat) -> Font {
return Font.custom("AvenirNextCondensed-Bold", size: size)
}
static func neutonRegular (size: CGFloat) -> Font {
return Font.custom("Neuton-Regular", size: size)
}
}
struct ContentView: View {
@StateObject var connectSession = MultipeerSession.shared
var body: some View {
VStack {
Circle()
.fill(Color.red)
.frame(width: 128, height: 128)
.onTapGesture {
let info = "stop".data(using: .utf8)
do {
let foo = connectSession.session.connectedPeers
try connectSession.session.send(info!, toPeers: foo, with: MCSessionSendDataMode.reliable)
} catch {
print("failed")
}
}.overlay(Text("STOP").font(Fonts.avenirNextCondensedBold(size: 48))
.foregroundColor(Color.white))
.padding()
Circle()
.fill(Color.green)
.frame(width: 128, height: 128)
.onTapGesture {
let info = "free".data(using: .utf8)
do {
let foo = connectSession.session.connectedPeers
try connectSession.session.send(info!, toPeers: foo, with: MCSessionSendDataMode.reliable)
} catch {
print("failed")
}
}.overlay(Text("GO").font(Fonts.avenirNextCondensedBold(size: 48))
.foregroundColor(Color.white))
.padding()
}
.padding()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment