Post

Replies

Boosts

Views

Activity

Send UDP Protocol is not working in Xcode 16 iOS18
func setupUDPSocket() { stopSearch() udpSocket = GCDAsyncUdpSocket(delegate: self, delegateQueue: DispatchQueue.main) do { try udpSocket?.bind(toPort: 4012) try udpSocket?.beginReceiving() try udpSocket?.joinMulticastGroup("239.255.255.250") } catch let error { DispatchQueue.main.async { print(Thread.current) print(error) print(error) } } } private func search() { guard let udpSocket = udpSocket else { print("not set udpSocket") stopSearch() return } let message = "M-SEARCH * HTTP/1.1\r\n" + "HOST: 239.255.255.250:1900\r\n" + "MAN: \"ssdp:discover\"\r\n" + "MX: 3\r\n" + "ST: ssdp:all\r\n" + "\r\n" let data = message.data(using: .utf8)! udpSocket.send(data, toHost: "239.255.255.250", port: 1900, withTimeout: -1, tag: 0) } This is my send SSDP code, my project was inited in Objective-C, recently I update xcode to 16, I get Error Domain=NSPOSIXErrorDomain Code=65 "No route to host", when I send UPD data in iOS 18, but iOS 17 is ok. Even I found, if I init a new project in Swift, this bug is disappear.
1
0
180
2w
Custom Sequence, use `for` index don't change, but `while` is normal. why?
struct BoxedFibonacciSequence: Sequence, IteratorProtocol { typealias Element = Int var currentIndex = 0 mutating func next() -> Int? { defer { currentIndex += 1 } return loadFibNumber(at: currentIndex) } func makeIterator() -> Self { return self } } func loadFibNumber(at index: Int) -> Int { return fibNumber(at: index) } var box = BoxedFibonacciSequence() for v in box { print("for index",box.currentIndex) if v < 20 { } else { break } } let fib = BoxedFibonacciSequence() var iter = fib.makeIterator() while let v = iter.next() { print("while index",iter.currentIndex) if v < 20 { } else { break } } //out put: //for index 0 //for index 0 //for index 0 //for index 0 //for index 0 //for index 0 //for index 0 //for index 0 //for index 0 //while index 1 //while index 2 //while index 3 //while index 4 //while index 5 //while index 6 //while index 7 //while index 8 //while index 9
1
0
275
Aug ’23
For a custom Sequence protocol, but index don't change, but use while index change. why?
struct BoxedFibonacciSequence: Sequence, IteratorProtocol { typealias Element = Int var currentIndex = 0 mutating func next() -> Int? { defer { currentIndex += 1 } return loadFibNumber(at: currentIndex) } func makeIterator() -> Self { return self } } func loadFibNumber(at index: Int) -> Int { return fibNumber(at: index) } var box = BoxedFibonacciSequence() for v in box { print("for index",box.currentIndex) if v < 20 { } else { break } } let fib = BoxedFibonacciSequence() var iter = fib.makeIterator() while let v = iter.next() { print("while index",iter.currentIndex) if v < 20 { } else { break } } why use for index always 0, but while index is normal? I'm confused.
0
0
237
Aug ’23
Swift Set type performance inconsistently when inserting data
This code will generate different result when RoadmapCardChain  implement Hashable  and Equatable  protocol struct RoadmapCardChain: Codable, Hashable, Equatable { &#9;&#9;let start: String &#9;&#9;let end: String &#9;&#9;let styles: String &#9;&#9; &#9;&#9;static func == (lhs: RoadmapCardChain, rhs: RoadmapCardChain) -> Bool { &#9;&#9;&#9;&#9;let isStyleSame = lhs.styles == rhs.styles &#9;&#9;&#9;&#9;let isEndSame = lhs.start == rhs.start &amp;&amp; lhs.end == rhs.end &#9;&#9;&#9;&#9;let isToggleEndSame = lhs.start == rhs.end &amp;&amp; lhs.end == rhs.start &#9;&#9;&#9;&#9;print(lhs) &#9;&#9;&#9;&#9;print(rhs) &#9;&#9;&#9;&#9;print("result is \(isStyleSame &amp;&amp; ( isEndSame || isToggleEndSame ))") &#9;&#9;&#9;&#9;return isStyleSame &amp;&amp; ( isEndSame || isToggleEndSame ) &#9;&#9;} } let a = RoadmapCardChain(start: "Cafeteria", end: "Payment BIZ", styles: "AECC5C") let b = RoadmapCardChain(start: "Payment BIZ", end: "Cafeteria", styles: "AECC5C") var chains: Set&lt;RoadmapCardChain&gt; = [] print(a.hashValue) print(b.hashValue) chains.insert(a) if chains.contains(b) { &#9;&#9;print("contains is true") } else { &#9;&#9;chains.insert(b) } print(chains) sometime result is : 785027920194053578 6404817261741129101 RoadmapCardChain(start: "Cafeteria", end: "Payment BIZ", styles: "AECC5C") RoadmapCardChain(start: "Payment BIZ", end: "Cafeteria", styles: "AECC5C") result is true contains is true [__lldb_expr_19.RoadmapCardChain(start: "Cafeteria", end: "Payment BIZ", styles: "AECC5C")] but sometime result is : 491382166321900052 7275567105868021174 [lldb_expr_21.RoadmapCardChain(start: "Cafeteria", end: "Payment BIZ", styles: "AECC5C"), lldb_expr_21.RoadmapCardChain(start: "Payment BIZ", end: "Cafeteria", styles: "AECC5C")] I don't know why same codes has different performance  I still don't understand why sometimes == be called and sometimes it doesn't be called。According to my understanding Set only need hashvalue when insert or contains function, don't need to call ==
1
0
418
Aug ’20