Post

Replies

Boosts

Views

Activity

Reply to Launch app by Target.
Now every time I hit compile, Xcode just launching my widget's Target by default, not my app's Target Have you chosen the right target you want to run on the Choose scheme button on the toolbar - https://help.apple.com/xcode/mac/current/#/devf0d1df47a of Xcode?
Jan ’21
Reply to Custom color management
Hi, this is my code : Thanks for showing your code, but maybe my words were not well representing what I wanted. But anyway, if you want some changeable color set, why don't you make it an environment object? import SwiftUI struct ContentView: View { 		@EnvironmentObject var colorManager: ColorManager 		var body: some View { 				Text("Hello, world!") 						.padding() 						//↓ Apply the changeable color 						.background(colorManager.spotifyGreen) 		} } class ColorManager: ObservableObject { 		@Published var spotifyGreen = Color("SpotifyGreen") 		//... } struct ContentView_Previews: PreviewProvider { 		static var previews: some View { 				ContentView() 						.environmentObject(ColorManager()) 		} }
Topic: App & System Services SubTopic: Core OS Tags:
Jan ’21
Reply to tableview.reloadRows() takes three hit to reload
so I just paste the necessary part here. Sorry, but it was less than necessary. What I am trying to do is that I try to reload the row of my tableview whenever user click on a specific row by doing all the logic inside the didSelectRowAt() method as I have stated above. Please show enough code to reproduce the issue. As I wrote I cannot reproduce the issue with your shown code.
Topic: Programming Languages SubTopic: Swift 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 { 		@State var toggle = true 		var body: some View { 				PreviewOnchangeTest(toggle: $toggle) 		} } struct PreviewOnchangeTest_Previews: PreviewProvider { 		static var previews: some View { 				ContainerView() 		} }
Topic: UI Frameworks SubTopic: SwiftUI 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 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