Post

Replies

Boosts

Views

Activity

Problem again with user-defined setting
This was something I needed so much help with in this post https://developer.apple.com/forums/thread/666997 I want to add a user defined setting. As I did (from the answer in the previous post, I made sure I was adding in SWIFTACTIVECOMPILATION_CONDITIONS I added MYDEBUG01, which does not work. This is in Xcode 12.4 I put up both projects in a picture, the one where it does work is the bottom one, MYSCENES. This was in Xcode 11.x The screens do look a little different, but can't figure out where my error is. Here is the screenshot http:// 98.7.37.117/index.html
2
0
1.8k
Feb ’21
How can I have an SKSpriteNode follow the same path back and forth?
My code is compartmentalized over many files, so I hope I can describe this easily. I have a path that goes from point A to point B I place an SKSpriteNode at point A and execute: iconPath[0] = the path SKAction.follow(iconPath[0], asOffset: false, orientToPath: false, duration: 1)) I execute that SKACtion and as I expected, my SKNode goes from point A to point B. Fine. I'm not sure how to reverse it, I assumed from the dox that calling that same SKAction as is, would make the SKNode go from point B to A.
2
0
657
Feb ’21
Is there a simple way to make a background fit the entire screen?
I have an SKScene, where I use an SKSpriteNode as the background. While the work I do below to make it fit to scale isn't much, I wondered if Swift provided a method or property that would do the same? From my GameScene override func didMove(to view: SKView){ super.didMove(to: view) self.backgroundColor = .clear let ratio = self.size.height / background.size.height background.size.height *= ratio background.size.width *= ratio background.anchorPoint = CGPoint(x: 0.0, y: 0.0) background.zPosition = -1 addChild(background) physicsWorld.contactDelegate = self self.isHidden = true From my main ViewController, where I create the GameScene let scene = WheelScene(size: myView.frame.size) scene.anchorPoint = CGPoint(x: 0.0, y: 0.0) scene.backgroundColor = .clear scene.scaleMode = .aspectFit wheelScene = scene mainView = myView myView.presentScene(wheelScene)
2
0
594
Mar ’21
Will casting "as?" fail if not the correct type?
I know this is a silly question, but I just want to be safe. I have multiple subclasses of SKSpriteNode in my app. In touchesBegan I am looking for a specific type, MyPeg. I just want to make sure that the code below fails if the node is not a MyPeg. I have this fear that if another of my subclasses is the same size, or too similar, or even has the same variables that I might get a positive. override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?){ super.touchesBegan(touches , with:event) guard let touch = touches.first else { return } let location = touch.location(in: self) let touchedNodes = self.nodes(at: location) for theNode in touchedNodes{ if let node = theNode as? MyPeg{
2
0
469
Jul ’21
Is Multiple inheritance not allowed in Swift?
So am watching a Speech To Text demo on YouTube, here: https://www.youtube.com/watch?v=SZJ8zjMGUcY There are no files, so am typing from the screen, and immediately run into an error that confuses me. at class ViewController : UIViewController, SFSpeechRecognizer { here's a screenshot: Swift gives me an error indicating that Multiple Inheritance is not allowed. The programmer doesn't have files to download, and I like to start from scratch anyway, typing and copying so I am forced to read each line. Is there something I have to change in the project itself that allows Multiple Inheritances? This video is from last year, and is on Swift 5.0. So I don't think there could be that much of a major change in Swift in that time. Thanks
2
0
2.6k
Nov ’21
Do child view controllers inherit the frame of their parents?
Below is my code. I have the ViewController, which takes up entire screen (set background color, makes sure status bar is visible, etc. It then calls up the MainController, which is set to be only in the safeAreaLayout frame. It has a button that brings up a third view controller when clicked. Everything works, the ViewController covers the entire screen, the MainController rests within the safeAreaLayouts of the iPhone X, and the third view controller comes up the same size and position as the MainController. It's that last part I want to make sure of, that that is the way it is supposed to come up. Can I count on that? Or must I set its frame myself to be sure? ViewController class ViewController: UIViewController { var mainController = MainController() override func viewDidLayoutSubviews() { super.viewDidLayoutSubviews() self.addChild(mainController) self.view.addSubview(mainController.view) setConstraints(vc: mainController, pc: view) } override func viewDidLoad() { super.viewDidLoad() view.backgroundColor = bgColor } override var prefersStatusBarHidden: Bool { return false } override var preferredStatusBarStyle: UIStatusBarStyle { return .darkContent } } func setConstraints (vc: UIViewController, pc: UIView) { vc.view.translatesAutoresizingMaskIntoConstraints = false var constraints = [NSLayoutConstraint]() constraints.append(vc.view.leadingAnchor.constraint(equalTo: pc.safeAreaLayoutGuide.leadingAnchor)) constraints.append(vc.view.trailingAnchor.constraint(equalTo: pc.safeAreaLayoutGuide.trailingAnchor)) constraints.append(vc.view.bottomAnchor.constraint(equalTo: pc.safeAreaLayoutGuide.bottomAnchor)) constraints.append(vc.view.topAnchor.constraint(equalTo: pc.safeAreaLayoutGuide.topAnchor)) NSLayoutConstraint.activate(constraints) } MainController class MainController: UIViewController { private lazy var countController = CountController() var invButton : MyButton! override func viewDidLoad() { super.viewDidLoad() view.backgroundColor = .black ...button code .... } override var prefersStatusBarHidden: Bool { return false } @objc func buttonAction(sender: UIButton!) { guard let theButton = sender as? MyButton else { return} self.addChild(countController) self.view.addSubview(countController.view) } } ThirdViewController class CountController : UIViewController { var backButton : MyButton! override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) } override func viewDidLoad() { super.viewDidLoad() self.view.backgroundColor = .gray } }
2
0
1.3k
Nov ’21
Is anyone aware of any bugs associated with: .modalTransitionStyle = .partialCurl ?
I posted this question below on StackOverflow, and when someone pointed out .partialCurl, I tried different modalTransitionStyles, and the code doesn't crash. Is anyone aware of "known" issues with partialCurl from Apple? original post on StackOverflow Within my root UIViewController I call up a submenu, second UIViewController, with the following code: within root UIViewController let myInvMenu = InvMenuCtrl() myInvMenu.modalPresentationStyle = .fullScreen myInvMenu.modalTransitionStyle = .partialCurl present(myInvMenu, animated: false) Within the new screen, I have a back button, I want dismiss it, and return to the original UIViewController. dismiss(animated: false) In this post, I have the animation set to false, because that works fine. But if I set it to true, I crash on the dismissal. From the docs, below I assumed that I didn't have to handle anything myself, but obviously if someone could tell me where my misunderstanding is: The presenting view controller is responsible for dismissing the view controller it presented. If you call this method on the presented view controller itself, UIKit asks the presenting view controller to handle the dismissal.
2
0
455
Mar ’22
Not sure why Swift is giving me a "Cannot find 'xFile' in scope" error
I have the following structure : struct XFile : Codable { ...variables here init(fileUrl: URL, key: String) { ... } Then in another class I am trying the following: class UploadTask { var xfile: XFile var inProgress = false init(file: URL) { xFile = XFile(fileUrl: file, key: "filename") } } If typed as above Xcode gives me the following error: Cannot find 'xFile' in scope If I remove the xFile= part, Xcode give me the following warning and error: Result of 'XFile' initializer is unused Return from initializer without initializing all stored properties Obviously I am breaking some rule, just not sure what it is.
2
0
857
Apr ’22
Can I calculate the bufferSize on .installTap to equal X seconds
Below is a quick snippet of where I record audio. I would like to get a sampling of the background audio so that later I can filter out background noise. I figure 10 to 15 seconds should be a good amount of time. Although I am assuming that it can change depending on the iOS device, the format returned from .inputFormat is : <AVAudioFormat 0x600003e8d9a0: 1 ch, 48000 Hz, Float32> Based on the format info, is it possible to make bufferSize for .installTap be just the write size for whatever time I wish to record for? I realize I can create a timer for 10 seconds, stop recording, paster the files I have together, etc. etc. But if I can avoid all that extra coding it would be nice. let node = audioEngine.inputNode let recordingFormat = node.inputFormat(forBus: 0) makeFile(format: recordingFormat) node.installTap(onBus: 0, bufferSize: 8192, format: recordingFormat, block: { [self] (buffer, _) in audioMetering(buffer: buffer) print ("\(self.averagePowerForChannel0) \(self.averagePowerForChannel1)") if self.averagePowerForChannel0 < -50 && self.averagePowerForChannel1 < -50 { ... } else { ... } do { ... write audio file } catch {return};}) audioEngine.prepare() do { try audioEngine.start() } catch let error { print ("oh catch \(error)") }
2
0
1.1k
Jul ’22
Is there a method to close files in Swift? Specifically AVAudioFile files?
I have no problem creating, and writing to AVAudioFiles. do { audioFile = try AVAudioFile(forWriting: destinationPath, settings: format.settings) print ("created: \(curFileLinkName)") } catch { print ("error creating file")} But is there a way to close the file? I've searched and all I could find was this very post on StackOverflow, which makes me wonder.
2
1
1.1k
Jul ’22