Post

Replies

Boosts

Views

Activity

Reply to Strange behaviour with dictionary + DateComponents keys in iOS17
Yep it appears that DateComponents no longer implements Hashable correctly. In the Swift REPL on Sonoma I get this: 1> import Foundation 2> var dc1 = Calendar.current.dateComponents([.year, .month], from: Date()) 3> var dc2 = DateComponents(year: 2024, month: 1) 4> print(dc1 == dc2) true 5> print(dc1.hashValue == dc2.hashValue) false The rule is: if two values are equal (according to their Equatable implementation) then their hashValue must also be equal. As seen here, this doesn’t hold. Here’s a clue to the cause: 6> print(dc1.isLeapMonth) Optional(false) 7> print(dc2.isLeapMonth) nil Looking at the source code here shows that hash(into:) does include isLeapMonth in the hash calculation. And now we can test that theory: 8> dc2.isLeapMonth = dc1.isLeapMonth 9> print(dc1 == dc2 && dc1.hashValue == dc2.hashValue) true
Topic: App & System Services SubTopic: General Tags:
Jan ’24
Reply to Why does the superview of a UITableViewController turns nil after unwindSegue ?
But this should be considered accessing a private view hierarchy (the containment for your view controller) which apps shouldn’t do. Note the superview is a UIViewControllerWrapperView which is an undocumented class internal to UIKit. If it’s not a view you create in your app, then it’s not safe to go add subviews to it or expect any particular behavior from it.
Topic: UI Frameworks SubTopic: UIKit Tags:
Dec ’23
Reply to Core Bluetooth Bug
Nobody can help with the error information in that format; please see points 5 and 8 in Quinn’s Top Fourteen DevForums Tips. But looking at the code, the signature for your delegate method isn’t correct: func centralManager(_: CBCentralManager, didDiscover: CBPeripheral, advertisementData: [String: Any], rssi: NSNumber) -> [Int] The return type of [Int] doesn’t match the protocol requirement (of no return type) and doesn’t make sense. This should have caused a compiler warning. If this method is actually getting called at run time, then the unexpected return value may cause undefined behavior, which could include sending your app off the rails with weird errors like that. What is the purpose of return BeaconRSSI in that method? Where is it attempting to return that value to? Even if it weren't crashing, Core Bluetooth calls the delegate method just to inform you of something (discovery of a peripheral) and wouldn’t know what to do with any value returned from it.
Dec ’23
Reply to Missing multiple imports in CoreBluetooth.framework
The error message says Unknown class name but CBCentralManagerDelegate is a protocol. Is your code trying to use it in a context where a class name is expected? Or if this doesn’t help, can you post a small snippet of your app code that triggers the error? Also note that CBCentralManagerDelegate is declared in CBCentralManager.h rather than in its own file.
Nov ’23
Reply to Unable to get WiFi rssi value
I want to create a function which will return the rssi value of currently connected WiFi network on my iPhone. You can’t. There is no API for that. Please see iOS Network Signal Strength for details. I guess that support is no longer provided in Swift. There never was such support, and in fact the approach used in that code sample (poking in a private view hierarchy) is never a supported way to do anything on iOS. See the section on But what about this code I found on the ’net? at the link above. So moving on, the question is: why do you want the Wi-Fi signal strength? See the Network performance section for discussion of why this usually isn’t what you want. Or is the signal strength desired for a totally different purpose?
Topic: Programming Languages SubTopic: Swift Tags:
Nov ’23