I'm trying to make a three column Split View where the sidebar determines the type of content, so I was hoping to have separate views drive the Lists for each content type, but I'm getting an issue where the selections get out of sync / don't highlight. For simplicity, I tested using a sidebar/detail Split View, as follows:
struct StringItem : Identifiable, Hashable {
let id = UUID()
let item : String
}
struct SimpleSplitView: View {
@State private var selString : StringItem?
let content = [StringItem(item: "Here"), StringItem(item: "There"), StringItem(item: "Everywhere") ]
var body: some View {
NavigationSplitView {
// This
List(content, selection: $selString) { c in
NavigationLink(value: c) {
Text(c.item)
}
}
// or this
ContentStringX(selection: $selString)
} detail: {
if let s = selString {
DetailStringX(item: s)
} else {
Text("Empty")
}
}
}
}
struct ContentStringX: View {
let content = [StringItem(item: "Here"), StringItem(item: "There"), StringItem(item: "Everywhere") ]
@Binding var selection : StringItem?
var body: some View {
List(content, selection: $selection) { c in
NavigationLink(value: c) {
Text(c.item)
}
}
}
}
struct DetailStringX: View {
var item : StringItem
var body: some View {
VStack{
Spacer()
Text("Detail String " + item.item)
Spacer()
}
}
}
Ignore for a moment that my sidebar has two sections, the behavior is the same whether "This" or "or this" are used alone. You can see the highlighted selection of "There" from the upper sidebar selection and the corresponding detail. If I select any of the items in the lower sidebar part (from the embedded child view ContentStringX the detail is properly passed, but the selection isn't highlighted. Is it ok to pass the binding from the parent to the child to the list?
Second curiosity, is if I had a simpler content array of just Strings and used id:.self, then the selection works from within the nested child (other problems happen with uniqueness).
Post
Replies
Boosts
Views
Activity
My code to show a list from a fetch that can be selected is (simplified) as follows
@FetchRequest(sortDescriptors: []) private var players: FetchedResults<PlayerEntity>
@State private var selectedPlayerID : PlayerEntity.ID?
var body: some View {
NavigationSplitView {
List(players, selection: $selectedPlayerID) { player in
Text(player.shortName ?? "")
}
.navigationTitle("Players")
} detail: {
if let id = selectedPlayerID, let player = players.first(where: {$0.id == id}) {
Text("Do Something")
}
}
}
I'm using the state variable of type ID PlayerEntity.ID? to hold the selection.
However, I noticed the sample app from migrating to SwiftData ("SampleTrips") is essentially doing it like this:
@FetchRequest(sortDescriptors: [SortDescriptor(\.startDate)])
private var trips: FetchedResults<Trip>
@State private var showAddTrip = false
@State private var selection: Trip?
@State private var path: [Trip] = []
var body: some View {
NavigationSplitView {
List(selection: $selection) {
ForEach(trips) { trip in
TripListItem(trip: trip)
//... removed some extra code
}
}
//... removed some extra code
.navigationTitle("Upcoming Trips")
//... removed some extra code
} detail: {
if let selection = selection {
NavigationStack {
TripDetailView(trip: selection)
}
}
}
The sample code is able to pass an optional managed object type Trip? to hold the selection rather than the ID type. When I try to replicate that behavior, I can't. Does anyone know what would be different?
I installed the new iOS beta on an iPhone 7, and I don't see the new details in maps, and I don't see the new Live Text features in photos / camera.
I didn't see anything in the release notes about required hardware...
I'm looking at the sample code in the CoreDataCloudKitDemo. Doesn't the remove (duplicate tags) method here have a bug, since it is modifying a copy of the tags but not reassigning them to the post?
private func remove(duplicatedTags: [Tag], winner: Tag, performingContext: NSManagedObjectContext) {
duplicatedTags.forEach { tag in
defer { performingContext.delete(tag) }
guard let posts = tag.posts else { return }
for case let post as Post in posts {
if let mutableTags: NSMutableSet = post.tags?.mutableCopy() as? NSMutableSet {
		 if mutableTags.contains(tag) {
mutableTags.remove(tag)
mutableTags.add(winner)
}
}
}
}
}
Here is a code snippet:
let dateFormatter = DateFormatter()
dateFormatter.locale = Locale(identifier: "en_US_POSIX")
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZZZZZ"
dateFormatter.timeZone = TimeZone(secondsFromGMT: 0)
let dateString = "2020-09-17T15:59:23Z"
let date = dateFormatter.date(from: dateString)
print(date)
with a breakpoint on the last line,
(lldb) p date
(Date?) $R0 = nil
(lldb) po date
▿ Optional<Date>
▿ some : 2020-09-17 15:59:23 +0000
- timeIntervalSinceReferenceDate : 622051163.0
(lldb)
It looks like variable view is showing the same issue. I'll be filing a bug shortly. Does anyone know a work around?
If I'm looking at a date from an actual iOS App Store receipt (in local verify), the date looks like
"2020-09-10T20:48:26Z"
which can be parsed by
dateFormatter.dateFormat = "yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'"
but the same date returned by StoreKitTest configuration would be:
"2020-09-10T13:48:26-0700"
which requires a different format parser
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZZZZZ"
I'd expect to not need to change this part of the parser, right? Or are both formats legitimate RFC 3339 date strings?
In an existing app, I quickly (and wrongly) stored the data of the app using the older state restoration APIs, which worked but of course had a big possibility of data loss. So I migrated the app to use UIDocument(s) and that is working much better.
I decided to maintain the state restoration path for the view restoration. However, one thing that has been troubling and messy is that there are two truths now, so the view controller update code is somewhat messy.
Consider the case of a text document and a scroll view which displays that text: Ordinarily, the document would contain the text, and and the app could save the scroll position using state restoration. When the app launches, first the snapshot is displayed (showing the text scrolled), then the state restoration code would run, so now the app knows the scroll position, then snapshot is removed but the data may not have loaded. So essentially, the app needs to save a portion of the text in order to render the view, but really the user can't edit or scroll because the document hasn't loaded.
I basically have a local structure that contains all the drawable data (edited any time I add a control) and update methods from the document and from state restoration. The actual view controller only draws from the local structure. Does anyone have any strategies to handle this synchronization better?
I'd note that the Apple example on state restoration (below) saves the app data with the state restoration, which is explicitly what the documentation says not to do.
https://developer.apple.com/documentation/uikit/uiviewcontroller/restoring_your_app_s_state
How long does it typically take before lab appointment requests are approved or rejected? Mine is still staying pending some 6 hours later.
Just thought it might help to tag older posts. Can that be done?
I'm wondering if anyone has seen this, or has a good workaround. Here is a sample of the code I've been using to render a view to a UIImage, in this case, the view is not on screen so I use the layer.render method let vc = UIStoryboard(name: storyboardName, bundle: nil).instantiateViewController(withIdentifier: identifier)
vc = CGRect.init(origin: CGPoint.zero, size: forSize)
let renderer = UIGraphicsImageRenderer(size: forSize)
retVal = renderer.image { (context) in
vc.view.layer.render(in: context.cgContext)
}On iPad and iPhone, the view gets appropriately resized to forSize, but in catalyst, it doesn't. In fact, on the vc, viewWillLayoutSubviews is not called in the catalyst case, whereas it is called by CALayer layoutIfNeeded in iPad/iPhone.Thoughts?
I'm having a similar issue as described in this stackoverflow. I have a UITest that generates screenshots but when I export, I get this warning without additional information. Anyone know how to fix this or if there are any good logs as to what is happening?https://stackoverflow.com/questions/58185911/xcode-11-xctestplan-cant-export-screenshots
I'm trying to add a scheme / configuration pair to test unlocked features without having to comment / uncomment code, so it seemed like the best practice was to duplicate my Debug config to Debug Unlock and add an UNLOCK to the Active Compilation Conditions and create a new Scheme. That worked fine, but I noticed that some linked 3rd Party Frameworks aren't being properly found because they only have Debug / Release defined as their configs, and it looks like the new config means those default to the Release config (and paths).Is there a way to make the Frameworks see the right config or to pass the Complication Conditions directly from the Scheme without needing a new config?