Post not yet marked as solved
Do you have any new insights on this problem? I'm seeing the same behaviour with URLSession tasks that keep accumulating in instruments.
Post not yet marked as solved
Thanks for the quick response Matt. - https://developer.apple.com/forums/profile/meaton I looked at your other post - https://developer.apple.com/forums/thread/132575 but that is demonstrating a TLV (type, length, value) framer. I was talking about separating frames using a separation character (or delimiter).
you will need to save previously read data so that it can fit into the next frame Hmm... Why should we be saving the old chunk's data while it is still available in NWProtocolFramer.Instance's parseInput(...) function. The old data (which you refer to as previously read data) is not lost (and I don't think it is marked read until you call deliverInput...(...) or return its length in parseInput(...)). The problem I am experiencing, is that the framer does not get the new data (but is stuck on the old data).
I made small GitHub repo where you can debug the problem: https://github.com/Dev1an/Simple-Framer
Could you explain how your other posts (TicTacToe & TLV) are relevant to this delimiting problem (where the message lengths are not known in advance)?
Were you able to resolve this issue?
Post not yet marked as solved
Hi thanks for the response.
connection.currentPath.remoteEndpoint is the broadcast address in my example.
I didn't use an NWListener, I called receiveMessage on the NWConnection from which I am sending the beacons. I did this because I need to listen to the port from which the beacons are sent.
How do I create a NWListener that binds to the same port my NWConnection uses to send the beacon?
Post not yet marked as solved
I think you might be mixing two different states in an incorrect manner. OK, you need @State for MyView's position that you want to drag around. But the size of it's parent should not be included as a @State variable in this View. It is someone else's state and you should not duplicate one state multiple times.
You can read the size of the parent using a GeometryReader or you can pass its size using constants. Code example of both possibilities in combination with draggable position are listed below
Reading parent size using GeometryReader
struct ContentView: View {
var body: some View {
MyView()
.frame(maxWidth: .infinity, maxHeight: .infinity)
.border(Color.green, width: 1)
}
}
struct MyView: View {
@State var relativePosition = CGPoint(x: 0.20, y: 0.2)
@State var relativeSize = CGSize(width: 0.1, height: 0.1)
var body: some View {
GeometryReader(content: rectangle(parent:))
}
func rectangle(parent: GeometryProxy) -> some View {
let absoluteX = relativePosition.x * parent.size.width
let absoluteY = relativePosition.y * parent.size.height
return Rectangle()
.frame(width: parent.size.width * relativeSize.width, height: parent.size.height * relativeSize.height)
.position(x: absoluteX, y: absoluteY)
.gesture(dragGesture(parentSize: parent.size))
}
func dragGesture(parentSize: CGSize) -> some Gesture {
DragGesture().onChanged { (drag) in
let relativeX = drag.location.x / parentSize.width
let relativeY = drag.location.y / parentSize.height
self.relativePosition = CGPoint(x: relativeX, y: relativeY)
}
}
}
Passing the size using constants
struct ContentView: View {
var body: some View {
GeometryReader { proxy in
MyView(parentSize: proxy.size)
.frame(maxWidth: .infinity, maxHeight: .infinity)
.border(Color.green, width: 1)
}
}
}
struct MyView: View {
let parentSize: CGSize
@State var relativePosition = CGPoint(x: 0.20, y: 0.2)
@State var relativeSize = CGSize(width: 0.1, height: 0.1)
var body: some View {
Rectangle()
.frame(width: parentSize.width * relativeSize.width, height: parentSize.height * relativeSize.height)
.position(absolutePosition)
.gesture(dragGesture)
}
var dragGesture: some Gesture {
DragGesture().onChanged { (drag) in
let relativeX = drag.location.x / self.parentSize.width
let relativeY = drag.location.y / self.parentSize.height
self.relativePosition = CGPoint(x: relativeX, y: relativeY)
}
}
var absolutePosition: CGPoint {
CGPoint(
x: relativePosition.x * parentSize.width,
y: relativePosition.y * parentSize.height
)
}
}
Post not yet marked as solved
Thanks for your reply. It is some kind of bug in macOS I think. Because when I try the same code on a different account, it works perfectly. But on my own user account it shows the bug.
I still have not figured out how to get the menu items to render correctly on my account though... 😞
Post not yet marked as solved
How to accomplish this?
By using geometry reader to get the parent width instead of using @State variables.
struct ContentView: View {
var body: some View {
MyView()
.frame(maxWidth: .infinity, maxHeight: .infinity)
.border(Color.green, width: 1)
}
}
struct MyView: View {
var body: some View {
GeometryReader { proxy in
Button("Update Width") {}
.frame(width: proxy.size.width * 0.4, height: proxy.size.height)
.background(Color.blue)
}
}
}
@Claude31: Indeed your answer doesn't help me in any way. I don't care whether you can create custom views or not, I was asking people to help me build my own custom views. But anyway...The VStack and HStack are actually quite a good match for this use case. The only thing I didn't understood yet was the way in which alignment guides were passed up the view hierarchy. I figured it out now and it turns out that I had to put the guide on the dividend instead of the divider line.So to summarize, here is the code I ended up with:struct AdditionView: View {
let left: Left
let right: Right
var body: some View {
HStack(alignment: .division) {
left
Text("+")
right
}
.fixedSize()
}
}
struct DivisionView: View {
let dividend: Dividend
let divisor: Divisor
let spacing: CGFloat = 3
var body: some View {
VStack(spacing: spacing) {
aligningDividend
Divider().overlay(Color.primary)
divisor
}
.fixedSize()
}
var aligningDividend: some View {
dividend.alignmentGuide(.division) { dividend in
dividend[.bottom] + self.spacing
}
}
}
extension VerticalAlignment {
private enum Divider: AlignmentID {
static func defaultValue(in context: ViewDimensions) -> CGFloat {
context[VerticalAlignment.center] + 1
}
}
static let division = Self(Divider.self)
}And that gives me nice and aligned divisions in additions 😎.
Post not yet marked as solved
If you want to bind your textfields directly to the entityName property you should make it an @ObservedObject like this:struct DetailView: View {
@ObservedObject var entityName: EntityName
var body: some View {
VStack {
TextField("Name", text: $entityName.name)
Toggle(isOn: $entityName.active) { Text("Active") }
}
}
}I don't know whether the $binding will also commit your changes or if you have to do that manually though.
Post not yet marked as solved
I think the onCommand(Selector, perform: ()->Void) https://developer.apple.com/documentation/swiftui/view/3367871-oncommandis made for that but I don't know how to use it or if it is already working.None of the `onCopyCommand`, `onCutCommand`, `func onDeleteCommand` and so forth seem to be working in beta 5.