Post

Replies

Boosts

Views

Activity

UICollectionView batch move items crashing with ghost insert
`UICollectionView` documentation is sparse at best. `performBatchUpdates`is a complete enigma. I have been trying to get all 4 (move, add, delete, reload) operations working correctly in the update space. I have some hope that Apple has correctly implemented the handling but I wish they would explain what on earth they are doing.Here is what I'm trying to get to work. I have two arrays with similar items in various orders and animate the changes. Simple right!? Here are the arrays: po newItems.map({ $0.representedID }) ▿ 3 elements - 0 : "5ccbdfd08d9b423a9bb78310ffe7e92b" - 1 : "9130a12b035543099f30a6cd9c6b6081" - 2 : "e0d1a52ed9f3440b859d47db4f4709f4" po previous.map({ $0.representedID }) ▿ 4 elements - 0 : "9130a12b035543099f30a6cd9c6b6081" - 1 : "458b0523c4104a4bbcb420dc01aeb143" - 2 : "e0d1a52ed9f3440b859d47db4f4709f4" - 3 : "5ccbdfd08d9b423a9bb78310ffe7e92b"You can see we lose one item between previous and new items and the rest shift around a bit.I have some logic to calculate the differences and process that in the perform batch updates which are below: Changes for section:0 Removing :[1] Moving from:0 to 1 Moving from:3 to 0 reloading :[2]This makes sense to make the previous turn into the new we remove 1, move item in 0 to 1, move item in 3 to zero and simply reload index 2.This crashes every time here: *** Assertion failure in -[UICollectionView _endItemAnimationsWithInvalidationContext:tentativelyForReordering:animator:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3683.300.2/UICollectionView.m:5744 *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'attempt to perform an insert and a move to the same index path (<NSIndexPath: 0xc000000000200016> {length = 2, path = 0 - 1})'Where is this magic insert coming from? Any ideas the algorithm they are using performing these changes?Here is the sequence of the batch changes: collectionView.performBatchUpdates({ model.applyChanges(changes) print("Changes for:\(section)") if !changes.removeIndexes.isEmpty { print("Removing :\([Int](changes.removeIndexes))") self.collectionView.deleteItems(at: changes.removeIndexes.map({ IndexPath(row: $0, section: section)})) } for (from, to) in zip(changes.moveFrom, changes.moveTo).sorted(by: { $0.0 < $1.0 }) { print("Moving from:\(from) to \(to)") self.collectionView.moveItem(at: IndexPath(row: from, section: section), to: IndexPath(row: to, section: section)) } if !changes.addIndexes.isEmpty { print("adding :\([Int](changes.addIndexes))") self.collectionView.insertItems(at: changes.addIndexes.map({ IndexPath(row: $0, section: section)})) } if !changes.reloadIndexes.isEmpty { print("reloading :\([Int](changes.reloadIndexes))") self.collectionView.reloadItems(at: changes.reloadIndexes.map({ IndexPath(row: $0, section: section)})) } }, completion: { _ in print("Done updating:\(section)") self.updateEmptyState() })
2
0
3.0k
Jun ’17
Unboxing protocol to concrete type in SwiftUI View
Using Swift 5.7 we're trying to use protocols for testing and mocking in our SwiftUI App. With any and some we're able to hold a heterogeneous list of protocols with self constraints which works perfectly. What we're running into now is that we can't undox the any Protocol into a concrete type for the view. Here's a basic example: protocol ItemProtocol: ObservableObject {     var id: String { get } } struct ListSection {     var id: Int     let title: String     let items: [any ItemProtocol] } protocol ViewModelProtocol: ObservableObject {     var sections: [ListSection] { get } } struct MyView<T: ViewModelProtocol>: View {   @ObservedObject     var viewModel: T     init(viewModel: T) {         self.viewModel = viewModel     }     var body: some View {         List(viewModel.sections, id: \.id) { section in             Section {                 ForEach(section.items, id: \.id) { item in                     RowView(item: item)                     // create view for some ItemProtocol                     Text("Hello Item")                 }             } header: {                 Text(section.title)             }         }     } } struct RowView<T: ItemProtocol>: View {     @ObservedObject     var item: T     init(item: T) {         self.item = item     }     var body: some View {         Text("Row View")     } } This will result in an error: Type 'any ItemProtocol' cannot conform to 'ItemProtocol' I had hoped that the any ItemProtocol would be unboxed to it's concrete type and a concrete type of View would be created.
3
1
1.7k
Jun ’22
Ethernet connection downgraded while asleep
Recently upgraded to the Ventura 13.4 beta (22F5037d) and I'm noticing that when my computer sleeps for a while (overnight, a couple hours) the ethernet connection drops from gigabit to 100baseT. When I wake up the computer it doesn't upgrade its connection back to gigabit. If I unplug/replug the cable it will autodetect gigabit. If I manually change the network connection to 1000baseT it will also negotiate and work. deactivating and reactivating the service will also get it back to gigabit. Swapping the cable made no difference. Using the power adapter vs the docks power didn't also didn't make a difference. Once the computer is on gigabit it will remain there while the computer is being used (9+ hours) it only downgrades once the computer goes to sleep. Mac is connected via thunderbolt to a cal digit TS4 dock which is then connected to a ubiquiti switch, not sure if that makes a difference (hopefully not!). Anyone else seeing this?
1
0
449
Apr ’23
Export Localization Build failing with Macros
Recently we introduced a macro to our workspace. Builds fine inside Xcode, as well as builds fine using xcodebuild. Seemed like everything was working perfectly until we went to export localizations. If we attempt to do it from Xcode itself it will fail as it attempts to build macOS (which is a totally different issue) We have this process automated though so it is being built via command line: This is the exact prompt we're running xcodebuild -exportLocalizations -localizationPath ../output -workspace <workspace>.xcworkspace -exportLanguage en -sdk iphoneos This will do the normal Xcode package/build graph resolution and generation and begin building. Eventually when it hits a use case of the macro it will fail. In each case when it fails it will have something like this: <unknown>:0: warning: compiler plugin not loaded: '<output-path>/<our-macro-package>; failed to initialize <path-to-usage>.swift:29:35: error: external macro implementation type '<our-macro-package>.<our-macro>' could not be found for macro '<our-macro>()' If I go to that output path I can see the macro package executable there. If I look in the build command for the file I can something that looks like this: ... -load-plugin-executable <output-path>/<our-macro-package>\#<our-macro-package> ... If attempt to build, without the -exportLocalizations flag, it works and builds just fine. I'm not sure what's happening here. Has anyone seen this? Macros+export localizations?
5
1
879
Oct ’23
Billboarding Anchor's Child Entity in RealityKit
Trying to find some answers on why billboarding isn't working when attaching to an entity that is a child of an anchor. I'm trying to billboard an attachment so that it remains pointed at the user wherever they're viewing the content from. For example, showing some context information over dynamic 3d model on the table top. Not baked into a Reality Composer pro scene. I pulled the component and system used in the various Apple example projects (Diorama) that have the billboarding system. Playing around with the system and component I can add a simple model entity to the scene, tag it with the component and it works perfectly, all the time. As the camera moves it tracks it perfectly. Even when nested under other empty entities or off center or oddly rotated. Great! Then I wanted to apply this to an attachment that is shown from a model entity that is anchored to a horizontal plane and all of the sudden it doesn't work at all. I create the anchor: let anchor = AnchorEntity(.plane(.horizontal, classification: .table, minimumBounds: [0.01, 0.01])) if let lookAtText = attachments.entity(for: "LookAtMe") { lookAtText.position = [0,0.5,0] lookAtText.components.set(BillboardComponent()) lookAtText.name = "Look At Me" anchor.addChild(lookAtText) } content.add(anchor) The attachment shows correctly above the anchor, as expected, and does rotate some, just totally wrong or stops, It does not billboard correctly, or even remotely correctly. if I switch the anchor.addChild to be a content.add it isn't in the correct place, but billboarding works. I don't understand why adding it as a child to the anchor entity suddenly breaks completely unrelated systems. Am I doing something wrong or is this some sort of privacy issue? I can't find any documentation that using the look at api from an anchored entity is somehow forbidden.
1
0
489
Mar ’24
Screen Corner Radius Border
I'd like an effect similar to the iOS 18 Siri, with a border/stroke extending around the view including the corner radius of the screen. This is challenging as "logically" the view is rectangular and those radii don't really exist. I've seen some posts around the web about _displayCornerRadius which appears to be what would work but it is private and as far as I can tell never mentioned anywhere else. Does anyone know of a way to achieve a border around a view that correctly wraps around the corners of the rounded screen? Currently using SwiftUI but open to any solutions.
3
0
557
Aug ’24