hmm, some progress. things compile now that i've changed phraseChangePublisher to this:
var phraseChangedPublisher: AnyCancellable {
Publishers.CombineLatest(leftWord.$currentWord, rightWord.$currentWord)
.map({
return $0.0 + $0.1
})
.debounce(for: 1.0, scheduler: RunLoop.main)
.sink { someValue in
print("someValue: \(someValue)")
}
}
Is AnyCancellable the best way to proceed here?
At this point the pipeline wasn't firing, even when the words were changing.
When I added the following ivar in my View:
let pipeline: AnyCancellable
init(model: PhraseModel) {
self.model = model
self.pipeline = model.phraseChangedPublisher
}
the pipeline code runs and behaves as expected. However when I change body to the following:
var body: some View {
HStack {
Text(model.leftWord.currentWord)
Text(model.rightWord.currentWord)
}
.onReceive(pipeline, perform: {_ in
print("hello")
})
}
I get a compile error at line2: "Unable to infer complex closure return type; add explicit type to disambiguate"
Any guidance on how to improve this?
(heavy sigh)
Post
Replies
Boosts
Views
Activity
Nice I like that. Thanks.
While I'm waiting for swiftUI 2 to get out of beta, I decided to use this:
@State private var selectedTabIndex = DefaultsManager.shared.selectedTabIndex
var body: some View {
TabView(selection: $selectedTabIndex){
SearchTabView()
.tabItem{
Text("Search")
}
.tag(0)
.onAppear(){
DefaultsManager.shared.selectedTabIndex = 0
}
SecondTabView()
.tabItem{
Text("Second")
}
.tag(1)
.onAppear(){
DefaultsManager.shared.selectedTabIndex = 1
}
And tolerate the tech debt of ensuring that tag values match the index values.
This is a duplicate of https://developer.apple.com/forums/thread/658465
thanks BabyJ. That did the trick!
My current plan is to replace dateSelected with a roll your own binding
let binding: Binding<Bool>: {
return Binding<Bool>(
get: {
return false
},
set: {
if $0 {
startFetch()
})
Doesn't feel great, but it appears to work
thanks @OOPer I like this alternative approach
Looks like I figured it out: Podcast needs to conform to ObservableObject
add the following line to Podcast's toggleSubscription function
objectWillChange.send()
3. in PodcastRowView replace @State with @ObservableObject
Thanks OOPer, your reply was exactly what I was looking for.
Any chance you can refer me to Swift Syntax documentation explaining in general what <Content: View> is?
alternatively/additionally, if I instead want to declare a hostingView var, what type would it use?var hostingView: NSHostingView<_____: _____>?if shouldUseFancyView() { hostingView = NSHostingView(rootView: FancyView(param: paramValue)) } else { hostingView = NSHostingView(rootView: mySwiftUIView = PlainView(param: otherParamValue))}
thank you :-)
Is it possible to attach a complete project? I've never had any success doing this.I have a vague memory of attempting to add an attachment here, and my post being stuck forever waiting for a moderator. Since then, I've tried to not include links/attachments.any time I tried to isolate the element that might be causing the problem, the problem disappeared. my full project has (I think) too complex a view hierarchy to include in-line.
Here is information from the Transport Delivery Log[2020-02-27 15:03:11 PST] <main> DBG-X: parameter OSIdentifier = Mac OS X 10.15.3 (x86_64); jvm=25.71-b02; jre=1.8.0-u131-b11-iTMSTransporter-b02[2020-02-27 15:03:11 PST] <main> DBG-X: parameter PackageName = 1500810344.itmsp[2020-02-27 15:03:11 PST] <main> DBG-X: parameter PackageSize = 116206776[2020-02-27 15:03:11 PST] <main> DBG-X: parameter StatisticsClientStartDateTimeZoneISO = 2020-02-27T15:03:11-08:00[2020-02-27 15:03:11 PST] <main> DBG-X: parameter TransporterArguments = -m upload -u mike.hollingshead@gmail.com -vp json -sessionid @env:8DCF23D0-E9CF-450E-BB91-C68579D97EE1 -sharedsecret **hidden value** -itc_provider XW6S2RV763 -f /var/folders/4q/8jpg98nx1gbgdm0cgz0mh_kc0000gp/T/52AFFAD9-430B-4B12-A7D4-042EDC2934DE/1500810344.itmsp -indicator true -v eXtreme -Dtransporter.client=TransporterApp -Dtransporter.client.version=1.1.1 (1171)[2020-02-27 15:03:11 PST] <main> DBG-X: parameter Version = 2.0.0[2020-02-27 15:03:11 PST] <main> DBG-X: parameter iTMSTransporterMode = upload[2020-02-27 15:03:11 PST] <main> INFO: id = 20200227150311-908[2020-02-27 15:03:11 PST] <main> INFO: iTMSTransporter Correlation Key: e135b0ac-c68d-4fcd-8bec-05d60f704c04-0001[2020-02-27 15:03:12 PST] <main> DBG-X: Apple's web service operation return value:[2020-02-27 15:03:12 PST] <main> DBG-X: parameter Errors = [An error occurred while trying to call the requested method validateMetadata. (1272)][2020-02-27 15:03:12 PST] <main> DBG-X: parameter EnableJWTForAllCalls = false[2020-02-27 15:03:12 PST] <main> DBG-X: parameter RestartClient = false[2020-02-27 15:03:12 PST] <main> DBG-X: parameter ErrorCode = 1272[2020-02-27 15:03:12 PST] <main> DBG-X: parameter ErrorMessage = An error occurred while trying to call the requested method validateMetadata. (1272)[2020-02-27 15:03:12 PST] <main> DBG-X: parameter Success = false[2020-02-27 15:03:12 PST] <main> ERROR: An error occurred while trying to call the requested method validateMetadata. (1272)[2020-02-27 15:03:12 PST] <main> DBG-X: The error code is: 1272[2020-02-27 15:03:12 PST] <main> INFO: JSON:{"msg":{"phase":"Upload","count":2,"description":"Operation failed","index":2},"messageType":"VerifyProgress"}[2020-02-27 15:03:12 PST] <main> DBG-X: Returning 1Package Summary:1 package(s) were not uploaded because they had problems: /var/folders/4q/8jpg98nx1gbgdm0cgz0mh_kc0000gp/T/52AFFAD9-430B-4B12-A7D4-042EDC2934DE/1500810344.itmsp - Error Messages: An error occurred while trying to call the requested method validateMetadata. (1272)