Post

Replies

Boosts

Views

Activity

Reply to MultipeerConnectivity data Convert to Dictionary
Instead of sending a String I would send a message (MyMessage) where you can include a type, for example: public struct MyMessage: Codable { var type: Int // 0=word, 1=answer var data: String // the string value public init(type: Int, data: String) { self.type = type self.data = data } } You will have to encode/decode this, then you can find what type of message you received: func session(_ session: MCSession, didReceive data: Data, fromPeer peerID: MCPeerID) { if let response = try? MyMessage.decode(from: data) { DispatchQueue.main.async { if response.type == 0 { self.dictionaryValues["word"] = response.data } else { self.dictionaryValues["answer"] = response.data } } } else { // deal with no data } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Apr ’21
Reply to MultipeerConnectivity data Convert to Dictionary
Yes, as I said, you have to encode/decode this. Try this: extension Encodable { func encode(with encoder: JSONEncoder = JSONEncoder()) throws - Data { return try encoder.encode(self) } } extension Decodable { static func decode(with decoder: JSONDecoder = JSONDecoder(), from data: Data) throws - Self { return try decoder.decode(Self.self, from: data) } } func randomWordSession() { guard let word = try? MyMessage(type: 0, data: dictionaryValues["word"] ?? "").encode() else { return } ... } func answerSession() { guard let answer = try? MyMessage(type: 1, data: dictionaryValues["answer"] ?? "").encode() else { return } ... }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Apr ’21
Reply to SwiftUI macOS: tracking the mouse in a view?
nice solution and article from SwiftUI-Lab. It seems you could achieve something similar with just the following: (let me know if this works for you) struct ContentView: View { var mouseLocation: NSPoint { NSEvent.mouseLocation } @State var overImg = false var body: some View { Image(systemName: "clock").resizable().frame(width: 444, height: 444) .onHover { over in overImg = over } .onAppear(perform: { NSEvent.addLocalMonitorForEvents(matching: [.mouseMoved]) { if overImg { print("mouse: \(self.mouseLocation.x) \(self.mouseLocation.y)") } return $0 } }) } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Apr ’21
Reply to Unable to present. Please file a bug.
Definitely something wrong with SwiftUI. Here is a simple example that shows "Unable to present. Please file a bug." on iOS, and does not work on Mac Catalyst. struct ContentView: View { @State var arr = ["1","2","3"] var body: some View { NavigationView { ScrollView { ForEach(arr, id: \.self) { name in NavigationLink(destination: Text("view \(name)")) { Text("to view \(name)").padding(5) } } } } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
May ’21
Reply to Unable to present. Please file a bug.
@bob_mosh, @shitingsand, your issues may not be related to the original NavigationLink problem. Show us some example code, maybe we can track down your particular issues. In my example I tried all sorts of things, @State, @StateObjects, @ObservedObject, var, etc.. without any impact.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
May ’21
Reply to TextEditor Problem, or me?
try this: struct ContentView: View { @State var text = "start text" init() { UITextView.appearance().backgroundColor = .clear } var body: some View { NavigationView { ZStack { Color.green.ignoresSafeArea() TextEditor(text: $text) } .navigationTitle("Notepad Test!") } } } or this, if you only want the text editor background color: struct ContentView: View { @State var text = "start text" var body: some View { NavigationView { TextEditor(text: $text).padding().colorMultiply(.green) .navigationTitle("Notepad Test!") } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
May ’21
Reply to Unable to present. Please file a bug.
yes it works with List, however even without ScrollView the message still shows, but it works on iPhone. On Mac Catalyst, if I include StackNavigationViewStyle it shows the "error" but it works, whereas without it it doesn't work at all. I'm now on macos 11.4 beta2, target ios 14.5, testing on ios 14.6 iPhone. struct ContentView: View { var body: some View { NavigationView { VStack { NavigationLink(destination: Text("view 1")) { VStack{ Text("to view 1").padding(5) } } NavigationLink(destination: Text("view 2")) { VStack{ Text("to view 2").padding(5) } } NavigationLink(destination: Text("view 3")) { VStack{ Text("to view 3").padding(5) } } } }.navigationViewStyle(StackNavigationViewStyle()) // } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
May ’21