Post

Replies

Boosts

Views

Activity

Reply to Firebase | Retrieving Data Error
I got Optional <null> for the output Thanks for showing the result. I'm not good at Firebase, but your users does not have a child node matching child(uid!). The result is representing there is no such data in your database. You should better learn how to access hierarchical objects in Firebase. As already noted, this is not a good place to learn the basics of third party library like Firebase.
Topic: Programming Languages SubTopic: Swift Tags:
Jan ’21
Reply to Using keypaths to add a value to a variable?
Maybe keypaths are the answer? That can be one way, there may be others. Why don't you simply use Dictionary? var inventory: [String: Int] = [ &#9;&#9;"blueBandages": 0, &#9;&#9;"redBandages": 0, &#9;&#9;"yellowBandages": 0 &#9;&#9;"greenBandages": 0 ] I haven't been able to make it work, because my key path is still acting like a string and not executable code Please show the code.
Topic: Programming Languages SubTopic: Swift Tags:
Jan ’21
Reply to Failed to produce diagnostic for expression; please file a bug report
Someone know how to fix that? Please try this: struct ContentView: View { &#9;&#9; &#9;&#9;@State var count: Int = 0 &#9;&#9; &#9;&#9;var body: some View { //error: "Failed to produce diagnostic for expression; please file a bug report"->gone, see `<-` &#9;&#9;&#9;&#9;VStack { &#9;&#9;&#9;&#9;&#9;&#9;Image("IMG") &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.padding(.trailing, 353.844) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.scaleEffect(0.3) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.fixedSize() &#9;&#9;&#9;&#9;&#9;&#9;Spacer() &#9;&#9;&#9;&#9;&#9;&#9;Text("Count:\(count)") &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.font(.largeTitle) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;.animation(.easeIn(duration: 0.5)) &#9;&#9;&#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;&#9;&#9;Spacer() &#9;&#9;&#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;&#9;&#9;Button("\(count)", action: { //<- &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;count += 1 &#9;&#9;&#9;&#9;&#9;&#9;}) &#9;&#9;&#9;&#9;} &#9;&#9;} } Button does not have an initializer taking Text and action closure in this order. And Text does not have an initializer taking Int. The current Swift compiler is too weak to diagnose type-related errors inside ViewBuilder, you should better send a feedback - https://developer.apple.com/bug-reporting/ as suggested. Some other things: In Swift, only type names should use Capital case identifiers. Property names should start with lowercase letter. Use @State, if you want to modify the value in some action closure. You should better use String Interpolation literals more, especially in SwiftUI.
Jan ’21
Reply to Help with documentation : example: DisclosureGroup
from this  struct DisclosureGroup<Label, Content> : View where Label : View, Content : View I expect to call disclosure with 2 view. but it does not seems to work.  Have you really read the Swift book? call disclosure does not make sense. Label and Content are the generic parameters, they are just a template and replaced to the actual types depending on the context. Test 2 - I tried this and it work You are calling the following initializer in this case:     public init(_ titleKey: LocalizedStringKey, @ViewBuilder content: @escaping () -> Content) It works because this initializer is defined. Not because generic parameters. Test 3: I tried to enter the Text view into the disclosure calling , did not work  but the content should be () -> Content and Text is taking an argument ... As the error message is clearly stating, content needs to be a closure. struct ContentView3: View { &#9;&#9;var body: some View { &#9;&#9;&#9;&#9;DisclosureGroup("Lightning", content: {Text("Fast")} ) &#9;&#9;} } Seems you do not understand the difference between a closure returning Text and Text itself. I recommend you to read the Swift book carefully. Test 4 with the last argument inside - calling a var of type some View - did not work There is no initializer in DisclosureGroup taking type name, nor any other Swift types. I recommend you to read the Swift book carefully. Test 5 with the last argument inside - calling a func that return some View - Worked  In Swift, function names can be used as a closure.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jan ’21
Reply to Builduing IOS apps
can I connect an iPhone to windows 10 and build ios apps? NO. Some development frameworks provides some ways to develop and test an app on simulators on Windows, but you need Mac to run such apps on your actual iPhone.
Topic: App & System Services SubTopic: Core OS Tags:
Jan ’21
Reply to Using keypaths to add a value to a variable?
how can I change a value in the dictionary when updating amounts? Like this: struct Product { &#9;&#9;var brand: String &#9;&#9;var option1: String &#9;&#9;var option2: String &#9;&#9;var item1: String &#9;&#9;var item2: String } var inventory: [String: Int] = [ &#9;&#9;"blueBandages": 0, &#9;&#9;"redBandages": 0, &#9;&#9;"yellowBandages": 0, &#9;&#9;"greenBandages": 0 ] //catalog let products = [ &#9;&#9;Product(brand: "Academia", option1: "Blue", option2: "Red", item1: "blueBandages", item2: "redBandages"), &#9;&#9;Product(brand: "Academia", option1: "Yellow", option2: "Green", item1: "yellowBandages", item2: "greenBandages"), ] let inventoryKey = products[1].item2 func buy() { &#9;&#9;inventory[inventoryKey, default: 0] += 1 }
Topic: Programming Languages SubTopic: Swift Tags:
Jan ’21
Reply to Using keypaths to add a value to a variable?
 I would have to put in an If or Switch statement to input the correct ending, but this can get messy.   If you want to choose the item with an integer value, you should better use Array: struct Product { &#9;&#9;var brand: String &#9;&#9;var option1: String &#9;&#9;var option2: String &#9;&#9;var items: [String] } var inventory: [String: Int] = [ &#9;&#9;"blueBandages": 0, &#9;&#9;"redBandages": 0, &#9;&#9;"yellowBandages": 0, &#9;&#9;"greenBandages": 0 ] //catalog let products = [ &#9;&#9;Product(brand: "Academia", option1: "Blue", option2: "Red", items: ["blueBandages", "redBandages"/*,...*/]), &#9;&#9;Product(brand: "Academia", option1: "Yellow", option2: "Green", items: ["yellowBandages", "greenBandages"/*,...*/]), ] &#9;&#9;@IBAction func buyButton(_ sender: UIButton) { &#9;&#9;&#9;&#9;let chosenItem = sender.tag &#9;&#9;&#9;&#9;let inventoryKey = products[productIndex].items[chosenItem] &#9;&#9;&#9;&#9;//... &#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;inventory[inventoryKey, default: 0] += 1 &#9;&#9;}
Topic: Programming Languages SubTopic: Swift Tags:
Jan ’21
Reply to ChildView in FullScreenCover is recreated every time if ContentView is updated
fullScreenCover is called and ChildEventView is recreated. I cannot reproduce the issue with the shown code. Maybe some hidden parts of your code may be affecting. Can you show enough code to reproduce your issue? But generally, initializers of any subviews may be called at any time in SwiftUI. You should not write code depending on when or how many times init is called.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jan ’21
Reply to Multiple ARSessionDelegates?
needs to relay the frame on to anyone else who is listening to it.  I'm not sure what the common pattern for doing this would be.  Isn't it clear under the fact that you can register only one delegate. One more, I do not understand why calling frequency can be the reason to use two classes.
Topic: Programming Languages SubTopic: Swift Tags:
Jan ’21
Reply to How do you add control transforms and value maps to CoreMIDI.MIDIThruConnectionParams?
I'm not good at MIDI, so just read Apple's documentations and very few articles on the web. (This - https://stackoverflow.com/questions/54871326/how-is-a-coremidi-thru-connection-made-in-swift-4-2 was the only useful one I found.) One thing sure is that using MIDIThruConnectionParams is very difficult even for experienced Swift programmers. You may need something like the following: import CoreMIDI /// Fixed size C-array UInt8[128] typealias MIDIValueMapValueType = (UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8) extension MIDIValueMap { &#9;&#9; &#9;&#9;init(_ array: [UInt8]) { &#9;&#9;&#9;&#9;assert(array.count == 128, "array needs to contain 128 elements") &#9;&#9;&#9;&#9;let value = array.withUnsafeBytes {bytes in &#9;&#9;&#9;&#9;&#9;&#9;bytes.load(as: MIDIValueMapValueType.self) &#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;self.init(value: value) &#9;&#9;} &#9;&#9; } extension UnsafeMutablePointer where Pointee == MIDIThruConnectionParams { &#9;&#9; &#9;&#9;var controls: UnsafeMutablePointer<MIDIControlTransform> { &#9;&#9;&#9;&#9;return ( &#9;&#9;&#9;&#9;&#9;&#9;UnsafeMutableRawPointer(self) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;+ MemoryLayout<MIDIThruConnectionParams>.stride &#9;&#9;&#9;&#9;).assumingMemoryBound(to: MIDIControlTransform.self) &#9;&#9;} &#9;&#9; &#9;&#9;var maps: UnsafeMutablePointer<MIDIValueMap> { &#9;&#9;&#9;&#9;return ( &#9;&#9;&#9;&#9;&#9;&#9;UnsafeMutableRawPointer(self) &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;+ MemoryLayout<MIDIThruConnectionParams>.stride &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;+ MemoryLayout<MIDIControlTransform>.stride * Int(self.pointee.numControlTransforms) &#9;&#9;&#9;&#9;).assumingMemoryBound(to: MIDIValueMap.self) &#9;&#9;} } func createMIDIThruConnectionParams( &#9;&#9;source: MIDIEndpointRef? = nil, &#9;&#9;destination: MIDIEndpointRef? = nil, &#9;&#9;controlTransforms: [MIDIControlTransform] = [], &#9;&#9;maps: [MIDIValueMap] = [] ) -> Data { &#9;&#9;let size = MemoryLayout<MIDIThruConnectionParams>.stride &#9;&#9;&#9;&#9;+ MemoryLayout<MIDIControlTransform>.stride * controlTransforms.count &#9;&#9;&#9;&#9;+ MemoryLayout<MIDIValueMap>.stride * maps.count &#9;&#9;var midiThruConnectionParams = Data(count: size) &#9;&#9;midiThruConnectionParams.withUnsafeMutableBytes {bufPtr in &#9;&#9;&#9;&#9;let paramsPtr = bufPtr.baseAddress!.assumingMemoryBound(to: MIDIThruConnectionParams.self) &#9;&#9;&#9;&#9;MIDIThruConnectionParamsInitialize(paramsPtr) &#9;&#9;&#9;&#9;// &#9;&#9;&#9;&#9;if let source = source { &#9;&#9;&#9;&#9;&#9;&#9;let thruSource = MIDIThruConnectionEndpoint(endpointRef: source, uniqueID: MIDIUniqueID(1)) &#9;&#9;&#9;&#9;&#9;&#9;paramsPtr.pointee.numSources = 1 &#9;&#9;&#9;&#9;&#9;&#9;paramsPtr.pointee.sources.0 = thruSource &#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;if let dest = destination { &#9;&#9;&#9;&#9;&#9;&#9;let thruDest = MIDIThruConnectionEndpoint(endpointRef: dest, uniqueID: MIDIUniqueID(2)) &#9;&#9;&#9;&#9;&#9;&#9;paramsPtr.pointee.numDestinations = 1 &#9;&#9;&#9;&#9;&#9;&#9;paramsPtr.pointee.destinations.0 = thruDest &#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;// &#9;&#9;&#9;&#9;paramsPtr.pointee.numControlTransforms = UInt16(controlTransforms.count) &#9;&#9;&#9;&#9;paramsPtr.pointee.numMaps = UInt16(maps.count) &#9;&#9;&#9;&#9;memcpy(paramsPtr.controls, controlTransforms, MemoryLayout<MIDIControlTransform>.stride * controlTransforms.count) &#9;&#9;&#9;&#9;memcpy(paramsPtr.maps, maps, MemoryLayout<MIDIValueMap>.stride * maps.count) &#9;&#9;&#9;&#9;//Do other initializations &#9;&#9;&#9;&#9;//paramsPtr.pointee.... = ... &#9;&#9;&#9;&#9;//... &#9;&#9;} &#9;&#9;return midiThruConnectionParams } let connectionParams = createMIDIThruConnectionParams( &#9;&#9;controlTransforms: [ &#9;&#9;&#9;&#9;MIDIControlTransform(/*...*/), &#9;&#9;&#9;&#9;//... &#9;&#9;] ) var connectionRef = MIDIThruConnectionRef() let status = MIDIThruConnectionCreate(nil, connectionParams as CFData, &connectionRef) (You may need to fix many parts and add more codes...) a Swift beginner. If you really are a Swift beginner, I would recommend not to use these structs directly in your Swift code. Find some third party frameworks that are more Swifty (sorry I do not know if any). Or learn how to interact with C-based APIs including pointers and C-structs with variable-length member for months, possibly for years.
Topic: Programming Languages SubTopic: Swift Tags:
Jan ’21
Reply to Help with documentation : example: DisclosureGroup
I guess I call the init when I create it ? True. You call init when creating a struct. (You may need to find the documentation of init. Not the header of the type.) I am old :-) I started way back on paper terminal and then on punch card :-)  Same as me. Maybe I am older than you but I don't think I'm too old to learn Swift. One advice, forget about C Sharp. Generics in C sharp and generics in Swift are different. Another advice, you should better include the chapter name/section name of the Swift book (especially in case you do not understand the descriptions). That may help both readers who want to answer to your question and yourself.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jan ’21
Reply to live preview problem
As far as I know, SwiftUI cannot manage static @State variables properly. Please try this: struct ContainerView: View { &#9;&#9;@State var toggle = true &#9;&#9;var body: some View { &#9;&#9;&#9;&#9;PreviewOnchangeTest(toggle: $toggle) &#9;&#9;} } struct PreviewOnchangeTest_Previews: PreviewProvider { &#9;&#9;static var previews: some View { &#9;&#9;&#9;&#9;ContainerView() &#9;&#9;} }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jan ’21