Post

Replies

Boosts

Views

Activity

NSAlert fails
I am a newbie here, first request. This is called-from and declared inside my viewcontroller class: func NrangeAlert() { let alert = NSAlert() alert.messageText = "N out of range" alert.informativeText = "use a number between 1 and 92" alert.alertStyle = .warning alert.addButton(withTitle: "OK") alert.runModal() print("Select a number between 1 and 92") }but fails to show the alert. It compiles.XCode Version 11.3.1 (11C504)Swift -versionApple Swift version 5.1.3 (swiftlang-1100.0.282.1 clang-1100.0.33.15)Target: x86_64-apple-darwin19.2.0It successfully prints to the debugger area.What am I missing?
4
0
694
Jan โ€™20
SwiftUI Button().frame()
macOS ProjectApple Swift version 5.1.3 (swiftlang-1100.0.282.1 clang-1100.0.33.15)Target: x86_64-apple-darwin19.3.0struct ContentView: View { @State private var newSetState = true var body: some View { VStack { HStack { if self.newSetState { Text(...... } }.font(.largeTitle).lineLimit(1).padding().fixedSize() HStack { if self.newSetState { Text( ...... } }.font(.largeTitle).lineLimit(1).padding().fixedSize() Button(LocalizedStringKey("๐Ÿ”„"), action: { self.newSetState.toggle(); self.newSetState.toggle() } ) .frame(width: 36, height: 36, alignment: .center) } }}Button functions, i.e., causes body to cycle again, but I cannot change its size. If set to .font(.largeTitle) as the Text that procedes it, the emoji gets its top truncated, even if frame is 136x136. (attempted to paste .png here, rejected). Apennding .scaledToFill() or .scaledToFit() does nothing.If I should post a bug to Apple, please post a url "how to:".
0
0
914
Jan โ€™20
SwiftUI Button() .frame()
struct ContentView: View { @State private var newSetState = true var body: some View { VStack { if self.newSetState || !self.newSetState { HStack { Text( ... Text( ... }.font(.largeTitle).lineLimit(1).fixedSize() HStack { Text( ... Text( ... Text( ... }.font(.largeTitle).lineLimit(1).fixedSize() Button("emoji", action: { self.newSetState.toggle() } ) .font(.largeTitle) .frame(width: 36, height: 86, alignment: .center) } } .padding([.top, .leading, .trailing]) .frame(width: 280, height: 280, alignment: .center) }}I'm guessing my previous post was kicked because of the emoji symbol.The issue remains: Button() does not respond to the frame() method, as all my other views do. Indeed, if I create a Text() view, .font(.largeTitle) is sufficient to "grow" the view. The VStack{} responds to .frame() adjustments. The result of the above code produces the emoji in .largeTitle format but its top is cropped even though it is well inside the frame. The shadowed button behind it is shorter and wider and itself only accepts taps. That is to say, the copped emoji extends above the button in its background but is cropped well below the frame bounds.I am currently attempting to code a substitute Button() of my own until Apple can correct this. ;-)
6
0
8.2k
Feb โ€™20
How to get a count of the characters allowed for use in url passwords in any language.
The documentation states CharacterSet and CharacterSet.urlPasswordAllowed are each a set, assuming a Swift set. As such I should be allowed to append ".count"."However, I get a compiler error: "Value of type 'CharacterSet' has no member 'count'".Inserting this into my code:for char in CharacterSet.urlPasswordAllowed { print(char) }compiler error:Type 'CharacterSet' does not conform to protocol 'Sequence'Which indicates CharacterSet isnota Swift set.Inserting this into my code:print(CharacterSet.urlPasswordAllowed)prints output to debugging area:<CFCharacterSet Bitmap>How then can I get a count of the characters allowed for use in url passwords in any language?I assume Apple has this set defined for every language that has a system font defined.
6
0
1.1k
Feb โ€™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
7k
Mar โ€™20
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.2k
Mar โ€™20
how to loop through array(s) of optionals
This comes up a lot (for years) and has me buggered. class Act: Codable { var a: Uint32 var b: [UInt32]?... var z: [UInt32]? init( ...vars...)}I want to do a simple sum on .nonzerobitCount for every var a through z.I can write code to check,e.g.,10. if Act.b != nil {for index in 0..<Act.b!.count { if Act.b?[index] != nil { totalBits += Act.b?[index].nonzeroBiCount } } }but even with copy and paste this is exhausting and cludgy.
15
0
4.5k
Mar โ€™20
SCNBox as bounding box
From the Xcode documentation I understand " For example, if you create a physics shape from an SCNSphere object, SceneKit simulates collisions for any object that passes within the sphereโ€™s radius."Now I am trying to create a bounding box, where particles inside are contained by the walls of the box. I had painstakingly constructed six individual walls to form such a box, but was hoping there is a parameter I missed that allows non-collisions inside an SCNBox and collisions as they try to leave the friendly confines.
0
0
495
Mar โ€™20
Apple Calculator precision
Does "Calculator:Version 10.15.4 (213.3)" use 64 bit precision? It fails to provide values sometimes, particularly when using scientific notation on physics constants where EE is around -54. I know the Mac handles such values properly when programmed with Xcode. I use RPN mostly with "Calculator", though that shouldn't matter.
0
0
346
Aug โ€™20
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
882
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.5k
Jan โ€™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
1.8k
Jan โ€™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
428
Mar โ€™21