Why doesn't this work? (Specifically, it crashes.)
struct Item: Identifiable, Hashable, Codable {
var id = UUID()
var name: String? = nil
}
private let defaults: [Item] = [
Item(name: "Bread"),
Item(),
Item(name: "Peanut Butter"),
Item(name: "Jelly")
]
struct ContentView: View {
@State var selectedItem = Set<Item>()
@State var showSheet = false
var body: some View {
VStack {
ForEach(defaults, id: \.self) { item in
Button(item.name ?? "<unnamed>") {
self.selectedItem.removeAll()
self.selectedItem.insert(item)
print("Selected item is now \(self.selectedItem)")
self.showSheet = true
}
}
}
.sheet(isPresented: self.$showSheet) {
let _ = print("selected item \(self.selectedItem)")
RenameSheet(name: self.selectedItem.first!.name ?? "<no name>") {
self.selectedItem.removeAll()
}
}
.padding()
}
}
Based on the output from the prints, it gets set when the button is clicked, but is then empty when the sheet is presented.
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
I put this into a file:
#if DEBUG
#warning("Building with debug")
#endif
It always warns when I build in Xcode -- even when I'm (allegedly) using the Release configuration.
I created a new scheme called "Release", and changed the Run > Build Configuration to "Release". (And then I went and changed everything from "Debug" to "Release" in the scheme.)
But I always get the warning. (In Xcode. If I use xcodebuild -configuration Release I don't get the warning.)
Now that I can build again, I'm back to experimenting, this time using Firebase. To display my items, I set up a Table, and this mostly works, barring a couple of minor, crashy details.
I've got
@State var selectedItems = Set<Item.ID>()
private var tableData: [Item] {
return self.items.sorted(using: self.sortOrder)
}
var body: some View {
Table(self.tableData, selection: self.$selectedItems, sortOrder: self.$sortOrder) {
TableColumn("Item", value: \.name)
TableColumn("Count", value: \.count) { item in
Text("\(item.count)")
}
}
Edited down a bit but that's the basics.
The two problems I've got are:
When I select a row, it flashes but does not stay highlighted
If I select the same row again, it crashes with:
Fatal error: Duplicate elements of type 'Optional<String>' were found in a Set.
This usually means either that the type violates Hashable's requirements, or
that members of such a set were mutated after insertion.
I put in a willSet for the selectedItems which was not particularly helpful.
This doesn't happen with the CoreData version, so I assume it's something wonky about Firebase. Or my limited skills.
Searching for this crash doesn't seem to show anything useful.
It tells me my certificate is bad (doesn't have a private key), and that it needs me to revoke it so it can generate a new one, and I do that, and it loops forever. Oh and I get email from Apple saying it's been revoked.
Not sure if it's related but I also can't use a Developer ID certificate. Also says it doesn't have a private key. I even generated a new certificate using openssl so I could make sure I had the private key and the .csr file and still no happiness.
I also managed to kill my login keychain at some point, because why not.
I've googled and stackoverflowed and nothing works.
This is on macOS 13.6.1, and Xcode Version 15.0.1 (15A507).
I am frustrated to the point of tears at this point.
As mentioned before, we have to network extensions for our app -- a transparent proxy provider, and a packet filter. We just started testing with multiple users, and I'm seeing what seem to me to be very strange results, but they get less strange if the states aren't system-wide.
Easiest case: I install while I'm logged in, we install the agents and daemons, start everything up, and the app then goes to activate both extensions. This starts with an OSSystemExtensionRequest for each, and when the completion delegate is invoked, I go to "connect" them, which is where the does the load/save preferences. Barring the apparent timing issue I filed a feedback on, this works.
If i then fast-user-switch to a second user, the agent once again starts, and goes through the same process -- it creates an OSSystemExtensionRequest to load them both, the delegate gets invoked, and then it does the connection functions for each. The behaviour might change slightly if the second user is already logged in, but I lost my notes there.
At the end of this, I am left with things in a weird-to-me state:
For the second user (not an admin), I see three entries in prefs/settings > Network -- one packet filter, and two TPPs. The two TPPs either appear 100% identical, in that they both have the same connection time, or one is connected and the other isn't.
For the first user (an admin), I sometimes see 1, 2, or 3 entries -- and the VPNs are not always shown as connected.
This is new behaviour for us, so either it's something I'm doing in the connection code, or something in the OS changed. The latter seems unlikely since the machine in question is still running macOS 12.6, but I don't test multiple users very often.
If the packet filter is global, and the TPP network connection is per user, this kinda makes sense (but why did we not notice it before?).
As I mentioned elsewhere, I am trying to add a packet filter to our app. I can load load the extension, but I am getting permission denied when I try to save the preferences with it.
I am building for release, using a Developer ID Application certificate (macOS, if that wasn't clear).
I am starting to worry that I can't do this except on an MDM-managed system.
The crash is at
do {
retval = try ModelContainer(for: schema, configurations: [modelConfiguration])
} catch {
fatalError("Could not create ModelContainer: \(error)")
}
When I first set it up, it complained (at run-time) about a lot of issues, mainly items not being optional and I apparently had a couple of @Attribute(.unique)s left. After I got rid of all of those, however, I get the crash there.
I assume this is an obvious thing that I am doing wrong, but I can't figure it out.
I didn't think it was possible, but a coworker showed me a screenshot with the SentinelOne content filter having the enabled button greyed out in sysprefs:
So how are they doing that?
We have a Transparent Proxy Provider, and a Packet Filter. They both get activated on app startup, and then when that's done, I call code to set the preferences to enable them.
That is basically done by having the request:didFinishWithResult: method check the identity of the request, determine whether it was activation or deactivation, and then call the appropriate function to do the preferences load/save dance.
However, from the logs, it looks like the preferences-handling code sometimes only gets called for one of them (and, strangely, almost always the packet filter).
Is this a known issue? I'd guess something about multiple calls to load/save preferences happening at the same time?
Continuing my standard weekend project of just playing with things, and I have a little inventory app. Basically something like
@Model
final class Room {
var id: UUID
var name: String
@Relationship(deleteRule: .cascade, inverse: \Item.room) var items: [Item]
}
@Model
final class Item {
var id: UUID
var name: String
@Relationship(deleteRule: .nullify) room: Room
}
Then in a SwiftUI view for each Room, I use another ItemsView that constructs a query predicate based on the room ID that is passed in. And then on that, I've got a sheet to edit it, which is passed in @Bindable var item: Item, and has a form to edit it, and cancel & save buttons. Standard stuff.
But if I edit the fields in the Item, they get reflected immediately, which, ok, that's actually what I wanted so yay. But the "Save" button calls context.save() while the "Cancel" button doesn't -- it calls context.rollback() (and I have auto-save off).
And the problem I've got is: when I do that, the ItemsView updates, in real time, but when I cancel, it doesn't update; I have to quit and relaunch the app to get that properly in sync.
The easiest change I can make, I presume, is to simply not use the passed in Item, but simply copy its values around to a new instance, but that won't update the item, so I'd have to delete it and re-insert it, or copy the fields back in the completion handler, or any number of things.
So my question really is: assuming what I just described makes sense, what's the proper way to deal with it?
I added a Home concept to my simple test program, which made the chain be Home has Rooms which have Items. But when I tried using something like
let homeID = self.room.home?.id ?? UUID()
_items = Query(#Predicate {
($0.room?.home?.id == homeID) == true
})
it complained about an illegal ternary. Fine, it's picky so I changed the Item model to have a computed property:
var home: Home? {
return self.room?.home?.id
}
but with that, it crashes at runtime, because it can't find the keypath to .home.
Is this all expected?
Only I do:
.sheet(isPresented: self.$showMoveItemSheet) {
MoveItemsView(items: Array(self.selectedItems), from: self.room)
.modelContext(self.context)
}
.modelContext(self.context)
and then in the MoveItemsView I have
@Environment(\.modelContext) var context
Hm, I'm setting the Query programmatically during init, would that be the cause? 'cause it does seem to work...
Again, none of this is really my choice: our project is multi-platform (specifically, at this time, Windows and macOS). As a result, the people who started 8 hours before I did picked CMake and vcpkg to handle build system generation and 3rd party dependencies. (TBF, I can't blame them for this, since this does work on a Mac, for at least a simple build.)
I want to support Apple Silicon, obviously. I can build native on my M1 MBP. (I could, theoretically, use lipo and create a universal bundle, but that would mean manually signing a handful of executables, and then the whole thing, unless I missed a way to do this much more easily?) We're using CircleCI for CI, or maybe github actions in the future.
I have not been able to figure out how to use CMake and vcpkg to do a cross build. Not even universal, just "build for arm64 on Intel mac". googling and searching these fora hasn't shown a lot that seems to work (mainly, I think, for the vcpkg side). Which is weird, because one of the things people use CMake for is to build Android and iOS apps, which generally does mean cross-compiling. Does anyone know how to do that?
I'm at the point where I'm looking at CocoaPods again -- but that will not work with CMake, so we'll have two completely different build systems, one of which requires a Mac with GUI to add/remove sources/targets.
I had dealt with this in cmake, and then forgotten about it -- now trying my Xcode-only test project, and it won't work, because the profile has -systemextension as a suffix, while the one Xcode generates doesn't.
Am I missing something in how to get Xcode to deal with this?
Topic:
Developer Tools & Services
SubTopic:
Xcode
Tags:
Xcode
Network Extension
Provisioning Profiles
I looked at other posts with this problem and didn't find anything that worked.
I used Keychain Access and Certificate Assistant to create a CSR; I uploaded that on the portal. Downloaded the certificate, and I get that error whenever I try to import it. I can import it into the System one, but then it's untrusted, and I still can't export it as a p12 file.
This is one of the few times I did everything by reading the documentation as I did it, so I'm very confused.
Topic:
Code Signing
SubTopic:
Certificates, Identifiers & Profiles
Tags:
Signing Certificates
Developer ID