Thanks for your response, David. I have more questions. Are there plans to have MusicLibrary "sit on top of" iTunesMusicLibrary? Alternately, is there a plan to have iTunesMusicLibrary return MusicKit types for Swift?
Thank you, Greg
Post
Replies
Boosts
Views
Activity
I should also clarify: I'm running this on macOS.
I just tested; it reproduces on iPad. However it works fine on iPhone.
Looks like this is related: https://stackoverflow.com/questions/73267638/how-to-run-task-or-onappear-on-navigationsplitview-detail-for-every-selectio
I re-watched the Demystifying SwiftUI and Data Essentials in SwiftUI WWDC sessions. I basically learned that the LoadingState I have above needs to be "extracted" from CategoryDetail and maintained in the CategoryNavigation*View as a [Category:LoadingState] dictionary. This way the state is persisted and associated with the Category.
I also used the modifier .task(id:) so that it would execute when the selection changed. It's also still tricky to understand the best way to show "this hasn't ever started loading yet".
enum Category: CaseIterable, Hashable, Identifiable {
case first
case second
var id: Self {
self
}
}
struct CategoryRow: View {
let category: Category
var body: some View {
Text("Row: \(String(describing: category))")
}
}
extension Binding {
public func defaultValue<T>(_ value: T) -> Binding<T> where Value == T? {
Binding<T> {
wrappedValue ?? value
} set: {
wrappedValue = $0
}
}
}
struct CategoryDetail: View {
enum LoadingState {
case none
case loading
case loaded
case error
}
@Binding var category: Category?
@Binding var loadingState: LoadingState
var body: some View {
Group {
if category == nil {
Text("Select A Category")
} else {
VStack {
Text("Category: \(String(describing: category))")
Text("LoadingState: \(String(describing: loadingState))")
}
}
}.task(id: category) {
guard let category else {
debugPrint("nothing selected")
return
}
guard loadingState == CategoryDetail.LoadingState.none else {
debugPrint("Early Exit \(String(describing: category)): \(String(describing: loadingState))")
return
}
loadingState = .loading
do {
try await Task.sleep(for: .seconds(2))
loadingState = .loaded
} catch {
loadingState = .error
}
}
}
}
struct CategoryNavigationSplitView: View {
@State var selectedCategory: Category?
@State var loadingStates : [Category : CategoryDetail.LoadingState] = [:]
var body: some View {
NavigationSplitView {
List(Category.allCases, selection: $selectedCategory) { category in
NavigationLink(value: category) { CategoryRow(category: category) }
}
} detail: {
CategoryDetail(category: $selectedCategory,
loadingState: (selectedCategory != nil) ?
$loadingStates[selectedCategory!].defaultValue(.none) :
.constant(.none))
}
}
}
struct CategoryNavigationView: View {
@State var selectedCategory: Category?
@State var loadingStates : [Category : CategoryDetail.LoadingState] = [:]
var body: some View {
NavigationView {
List(Category.allCases, selection: $selectedCategory) { category in
NavigationLink {
CategoryDetail(category: $selectedCategory,
loadingState: (selectedCategory != nil) ?
$loadingStates[selectedCategory!].defaultValue(.none) :
.constant(.none))
} label: {
CategoryRow(category: category)
}
}
}
Text("Select a Category")
}
}
I just created a new macOS SwiftUI Project, and imported another SwiftUI library (using File → Swift Packages → Add Package Dependency). In the simple app's ContentView, I imported the module and added the new random SwiftUI view. I did Command-R, which is a Debug configuration by default, and it builds and runs, and shows the library UI.
If I then xcodebuild -verbose -configuration Debug it has the same problem. It has the same problem if I remove -configuration Debug. When compiling app Swift code, the compiler cannot find the module defined by the swift package manager.
/Users/bolsinga/Desktop/SPMText/SPMText/ContentView.swift:9:8: error: no such module 'MovingNumbersView'
import MovingNumbersView
^
How do I "inspect" a swift module? I may be able to learn it is being built incorrectly. How do I inspect where the swift compiler is "looking" for swift modules? I may be able to learn why it isn't looking in the right places.
Thanks for any tips! Perhaps there is a better place to ask this question?
I've also tried here: https://github.com/apple/swift-package-manager/issues/6074
Thanks to the GitHub issue, I learned that SPM and legacy builds (which I think is the -configuration) do not work together. The trick is to xcodebuild -list, gather the scheme name you want to build, and then use xcodebuild -scheme <name-of-scheme>.
FWIW My app is a full SwiftUI lifecycle app, so it is using onOpenURL.
My app is on macOS too. By reading the transcripts of https://developer.apple.com/videos/play/wwdc2020/10098/, I found swcutil. Here is its output of sudo swcutil show --verbose. I have not denied it.
Service: applinks
App ID: D3F44CA7F4.gdb.SiteApp
App Version: 1.0
App PI: <LSPersistentIdentifier 0x11f61dd80> { v = 0, t = 0x8, u = 0x7134, db = 2183ADB1-C496-48F1-B7FF-1301111FE8A7, {length = 8, bytes = 0x3471000000000000} }
Domain: www.bolsinga.com
User Approval: unspecified
Site/Fmwk Approval: denied
Flags:
Last Checked: 2023-06-12 21:37:13 +0000
Next Check: 2023-06-17 21:09:09 +0000
I found openul:
$ sudo swcutil --verbose openul -u https://www.bolsinga/com/dates/sh624.html
NSOSStatusErrorDomain -10814 {
_LSLine: "763",
_LSFunction: "+[LSAppLink(Internal) _openWithAppLink:state:completionHandler:]"
}
#wwdc20-10098
@eskimo Hi! Thanks so much. What is this new download? Is it related to this problem? Do we install it on the VM or in the host? https://developer.apple.com/download/ Regardless, I tried on the host and the VM w/o success.
How do we update our VM running macOS 14 beta 1 to beta 2? Thanks!
Device Support for macOS 14 beta 2
Install Device Support for macOS 14 beta 2 if installing the macOS Seed in a virtual Machine fails on a host Mac.
Released
June 21, 2023
Build
1700B21
Download Device Support Image
Device Support for macOS 14 beta 2
1700B21
It works great now that the CDN has caught up. Thanks again!
Thanks! This is terrific.
See https://github.com/apple/swift-package-manager/issues/6993 At least I found a workaround. xcstrings no longer need the "en.lproj" directory, and it appears maybe SPM is looking for that. If I add a "fake" file in that directory it will build!