Post

Replies

Boosts

Views

Activity

Integrate Metal/ObjC Tutorial into SwiftUI
I have modified Apple's Tutorial "CPU-GPU-Synchronization.xcodeproj" to suit my needs but cannot see how to launch it, e.g., as a sheet, from a Button inside a SwiftUI App. I found this: "developer.apple.com/forums/thread/119112" which establishes the Coordinater wrapper, device and CommandQueue, etc., but how do I "replace?" those already established in ObjC code? For example, ObjC does not recognize SwiftUI struct's and I can't @objc preface a SwiftUI struct as I can a SwiftUI class(ref. the above thread). Alternatively, is this the best venue to ask Apple to update/integrate their tutorials? Thanks.
6
0
2.1k
Mar ’21
EnvironmentObject update timeliness
My ContentView has an @EnvironmentObject and a few @State var's. The State vars are for use in TextFields, one can use a Picker or manual entry, and works fine. The other State var is to have its value set when the user hits a Button whose action executes a host of functions that changes the values of over twenty @Published vars monitored/updated by the @EnvironmentObject vis-a-vis Combine. This TexField must also be manually set/edited when desired. Within that same Button(action:{}) the next line of code attempts to set a State var to the value of the Published EnvironmentObject that had been changed by all those functions in the previous line. The problem is: the EnvironmentObject is not updated by the time this line of code is executed. Such that the Button must be pressed twice for the result to change the TextField. I have scoured the web and did not find, or did not understand, what is amiss. I have successfully used .id(UUID()) on Views to ensure updates, but this issue is within a Button/action and I wouldn't know how to implement it here as TextField is a struct, and I can't implement a View.id(UUID()) inside the Button. So far as I know. Thanks.
1
0
478
Mar ’21
SwiftUI SceneKit populated but not displayed
I am porting a functioning Swift App to SwiftUI with the ambitious intention of Multiple platform coding, so the project was created as such. I've worked out every issue except as the title suggests. My pertinent code: import SwiftUI import SceneKit struct ContentView: View { var scene : SCNScene = SCNScene = { () -> SCNScene in          //  DO NOT REPLACE OR MODIFY THE FIRST AND LAST LINES OF THIS VAR DECLARATION, e.g., "var scene:SCNScene{ ... }"  else initScene(newScene) FAILS to create children! let newScene = SCNScene() initScene(newScene)                            //  adds ChildNodes named: "precession" & "nuclearSpin" let newCamera = SCNNode() newCamera.position = SCNVector3(x: 0, y: 0 ,z: 40) newCamera.name = "cameraNode" newCamera.camera = SCNCamera() newScene.rootNode.addChildNode(newCamera) 10. newScene.fogDensityExponent = 0.0 return newScene }() @EnvironmentObject var structures:Structures @State private var Ncv = Int() @State private var indexMomentcv = Int() var body: some View { ZStack{ 20. SceneView( 21. scene: scene, 22. pointOfView: scene.rootNode.childNode(withName: "cameraNode", recursively: false), 23. options: [.allowsCameraControl, .autoenablesDefaultLighting, .temporalAntialiasingEnabled] 24. ).colorInvert() 25.             VStack(alignment: .trailing){ 26.                 Group{ 27.                     HStack{ 28.                         VStack{ // ... and so on 29. I have verified the existence of all nodes created for the scene, i.e., the objects to be seen, using these useful functions: func printChildNodeHierarchy(node: SCNNode) { node.enumerateChildNodes( { (anyNode,false) -> Void in return print( anyNode ) } ) }  //  SUPER handy func printChildNodeTransform(node: SCNNode) { node.enumerateChildNodes( { (anyNode,false) -> Void in return print( anyNode.name!,"\t", anyNode.simdTransform,"\t",anyNode.scale ) } ) } func printChildNodeAction   (node: SCNNode) { node.enumerateChildNodes( { (anyNode,false) -> Void in return print( anyNode.name!,"\t", anyNode.hasActions,"\t",anyNode.actionKeys ) } ) } ...which print in the debugging area. I have verified the materials assignments to the elements of those nodes. So, everything is in place as in the functioning Swift/macOS App but I just don't see the objects. What I've tried: Since I run in DarkMode theme I have cycled through the combinations of Dark/Light and with/without line 24's .colorInvert() and swapping ZStack with HStack. Some combo's do wash-out, but still no objects. I zero'd out the fog thinking it might be too foggy. Not. I've created a scene.scn file as a resource, applied the above attributes to it, reference it with scene = SCNScene(named: scene.scn"), but get the same non-result. Idk if some checkbox is errant in the build/target etc. area. Wouldn't know if it was. I'm not a professional programmer. Any thoughts are appreciated. I've been stuck for days. oh yeah: as of this posting I am up to date on all Apple software, running 2018 MacMini/Intel/SSD
2
0
2k
Jan ’21
App does not use my permissions to create dir
I've written an Switft/macOS App that creates directories deep within its own hierarchy. (no problem). Porting to SwiftUI means these directories and files should go(default) to ~/Documents. Since my Documents dir is (chmod -r 700) the ported app cannot write due to permissions. Which begs he question: what ID does the running app use? I found: https://developer.apple.com/forums/thread/82503?answerId=249036022#249036022 and it did change Xcode's : kMDItemFSOwnerGroupID                   = 20 kMDItemFSOwnerUserID                    = 502 but it still does not write as though it has my permissions. Aside from changing my ~/Documents dir permissions, how do I make my App (build/run within Xcode) as me so it can write?
5
0
1.8k
Jan ’21
FYI: Playing a movie using AVPlayer in Big Sur
took a bit of experimenting... import AVKit    //  macOS & iOS class ViewController_myShow: NSViewController {          @IBOutlet var myMOV: AVPlayerView! 10.          override func viewDidLoad() {         super.viewDidLoad()                  let playerView = AVPlayerView() 20. 21.         playerView.translatesAutoresizingMaskIntoConstraints = false 22. 23.         view.addSubview(playerView) 24. 25. 26. 27.         playerView.leadingAnchor.constraint  (equalTo: view.safeAreaLayoutGuide.leadingAnchor ).isActive = true 28. 29.         playerView.trailingAnchor.constraint (equalTo: view.safeAreaLayoutGuide.trailingAnchor).isActive = true 30. 31.         playerView.topAnchor.constraint      (equalTo: view.safeAreaLayoutGuide.topAnchor     ).isActive = true 32. 33.         playerView.bottomAnchor.constraint   (equalTo: view.safeAreaLayoutGuide.bottomAnchor  ).isActive = true 34. 35. 36. 37.         playerView.controlsStyle = .floating 38. 39.         playerView.showsFrameSteppingButtons   = true 40. 41.         playerView.showsFullScreenToggleButton = true 42. 43.          44. 45.         guard let path = Bundle.main.url(forResource: "myMovie", withExtension: "mov") else { return } 46. 47. 48. 49.         let player = AVPlayer(url: path) 50. 51.             playerView.player = player 52. 53.         playerView.player?.play()   54. 55.     } 56. 57. } The StoryBoard:AttributesInspector:AVPlayerView settings don't work for me... exactly. I had to set StoryBoard:AttributesInspector:AVPlayerView:ControlsStyle:none then include lines 37-41 in my code. The default is StoryBoard:AttributesInspector:AVPlayerView:ControlsStyle:inline which appears on screen but does nothing, i.e., no control. Line 21 is also required to be false. The .mov file can be File:AddFilesTo 'd or copied to Assets.xcassets see also: Developer Forum: "can't get extremely simple macOS video player to work..." https://developer.apple.com/documentation/avfoundation/media_playback_and_selection/creating_a_basic_video_player_macos 			
1
0
993
Jan ’21
SceneKits future
I have developed an app using SceneKit since Swift came out. Now SwiftUI is out and uses structs rather than classes. SceneKit is a cascade of classes. As a newbie, I am concerned that my code might be obsolete through depreciations soon after publication and I'd rather get ahead of the issues now. So, is SceneKit long-term viable? My first attempts at converting my custom classes to structs seems impossible without Apple leading the way. If I understand correctly, I can make a struct whose only member is an instance of a class, but the benefits of the struct, e.g., minimal memory, processing time, etc., are lost.
13
0
7.9k
Mar ’20
swift Process() return values
How do I access a returned value from a Process(), in this case 'which'... var sips_path : String? //MARK: locate sips on local machine let which_sips = Process() which_sips.executableURL = URL(fileURLWithPath: "which") which_sips.arguments = ["sips"] do { sips_path = try which_sips.run() } catch let error as NSError { sips_path = "/usr/bin/sips"; print("Failed to execute which_sips", error) }line 8. gets compiler error "Cannot assign value of type '()' to type 'String?'" I believe, but cannot prove, 'which' returns a string. .run() throws and throws are for errors only, right? So where is the result of calling which?It seems I should use a closure to use $0 but it's already in one...line 9. intends to assign a default path.
13
1
7.7k
Mar ’20