Within my code to fetch data from CoreData I have the following line:
let itemNoSort = NSSortDescriptor(key:"itemNo", ascending: false)
What I am not sure of however is that the above is the same as saying descending: true
Can't seem to find it in the documentation.
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
I would like to open an audio file on my iOS device and remove long silences. I already have the code for calculating volumes so am not pasting that here.
What I am unsure of "how to do" is: While I believe that I have the proper code to read the file below, I am unsure as to how to read it in proper pieces to I can later get the volume of each piece.
I realize that this might be a situation of calculating the size of frames and whatnot. But I am totally green when it comes to audio.
I would seriously appreciate any guidance.
guard let input = try? AVAudioFile(forReading: url) else {
return nil
}
guard let buffer = AVAudioPCMBuffer(pcmFormat: input.processingFormat, frameCapacity: AVAudioFrameCount(input.length)) else {
return nil
}
do {
try input.read(into: buffer)
} catch {
return nil
}
Using Xcode 15.0.1
The playground, for the code below, has been in "Launching ok" for over two minutes. Anything that I should look into? A little mind boggling actually.
import UIKit
var msg = "Hello World"
print ("\(msg)")
So like the title says, when I start up Xcode the preview won;t work till I run a debug session using the simulator.
Sometimes the debug session is unable to start the simulator, which I can start manually then run a debug session.
Once all the above is done, preview works.
Any idea what is causing this behavior?
Is there a Finder type app that will read through my iPhone files?
I’m working on a app that records audio files to my iPhone, and it would be much easier if I could find an app where I could scroll through the files on my iPhone from my desktop as opposed to doingit on the iPhone itself.
I am writing a SwiftUI based app, and errors can occur anywhere. I've got a function that logs the error.
But it would be nice to be able to call an Alert Msg, no matter where I am, then gracefully exits the app.
Sure I can right the alert into every view, but that seems ridiculously unnecessary.
Am I missing something?
My app needs a database and I would like to use SQLite.
Other than
using import SQLite3
and
adding libsqlite3.tbd in the Build Phase
Are there any other files I need to copy or import into my project?
myGV is a structure where I store a handful of global variables.
The following are all sub-classes of SKSpriteNode: I have a class called guessingBar which holds 6 guessSlots. The former class has an array of the guessSlots for me to loop through.
I just don't know the syntax of how to access the array.
myGV holds multiple variables, so the SKSpriteNode guessBar can be found at:
myGV.guessBar
I expected to be able to read the array with:
myGV.guessBar.guessSlots[x] but as you can see from the debugger screenshot, I cannot.
In the screenshot you can see that everything is initialized. Am I missing some silly typo, or is the syntax escaping me?
http: //98.7.37.117/s.png
I would like to take this sample code
override func viewDidLoad() {
super.viewDidLoad()
let button = UIButton(frame: CGRect(x: 100, y: 100, width: 100, height: 50))
button.backgroundColor = .greenColor()
button.setTitle("Test Button", forState: .Normal)
button.addTarget(self, action: #selector(buttonAction), forControlEvents: .TouchUpInside)
self.view.addSubview(button)
}
func buttonAction(sender: UIButton!) {
print("Button tapped")
}
...and place the code to create the button in another file. So it would look more like this:
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
makeButton(vControl: self)
}
@objc func buttonAction(sender: UIButton!) {
print("Button tapped")
}
}
Of course the main flaw is that I would have to pass a pointer to the function buttonAction.
Something like we do in C
makeButton(vControl: self, bFunc: &buttonAction)
Have Googled a lot but can't seem to find the way to do this. How do I set up the makeButton page to recieve this?
func makeButton (vControl: ViewController, bFunc: ???)
What would the ??? be in reality?
thanks
Below is a simple code patch I use to create a custom button, am new at this. I noticed the text does not appear and am wondering what the proper method is for making the text appear?
func makeButton (vControl: ViewController, action: Selector) {
let myButtonImage = UIImage(named: "Picture1.png")
let imageScale = myButtonImage!.size.width / myButtonImage!.size.height
let wwidth = vControl.self.view.bounds.width
let button = CreateButton(frame: CGRect(x: 100, y: 100, width: (myButtonImage?.size.width)!/3, height: (myButtonImage?.size.height)!/3))
button.setImage(myButtonImage, for: .normal)
button.backgroundColor = .clear
button.setTitleColor(.black, for: .normal)
button.setTitle("Test Button", for: .normal)
button.addTarget(vControl, action: action, for: .touchUpInside)
vControl.view.addSubview(button)
button.center = vControl.view.center
}
Thanks to people on this board I am able to successfully calla up a child UIViewConroller via animation with:
This is the buttonAction from the Main UIViewController, which calls up setController
@objc func buttonAction(sender: UIButton!) {
guard let theButton = sender as? MyButton else { return}
UIView.transition(with: self.view, duration: 0.5, options: .transitionCurlDown, animations: { [self] in
self.addChild(setController);
self.view.addSubview(setController.view);
}, completion: { [self]_ in setController.didMove(toParent: self);
setController.doLayout();})
}
the doLayout method lies within the child:
func doLayout (){
guard let parent = cView!.view.superview else {return}
//make sure UIV honors safeAreaLayouts
setConstraints(vc: self, pc: parent)
}
A button within the child, setController, dismisses itself:
@objc func buttonAction(sender: UIButton!) {
self.willMove(toParent: nil)
self.removeFromParent()
self.view.removeFromSuperview()
self.dismiss(animated: false, completion: nil)
}
Everything works great the first time I call up the child UIView. It curls down while covering the first/parent UIVIEW, etc. etc. Figure 1 But after I dismiss the child view and call it again, the child view scrolls down without really covering the main view, it's like a mishmash. Figure 2 Only after all is said and done, then the child view covers everything.
So am curious if I am dismissing something incorrectly.
I created the playground below to answer my question "If I created a class instance using DispatchQueue.global().async would that class remain in its own asynchronous queue? Even if the main app called one of that classes methods, would that method run asynchronously compared to the main app?
With the sleep line I discovered that the answer is "no."
But I am curious if there is a legit way to do this? Or even if there is, it is considered bad programming?
import UIKit
class MyFunx : NSObject {
var opsCount = 0
override init() {
super.init()
}
func addValues (a: Int, b: Int) {
let c = a + b
opsCount += 1
sleep(1)
}
}
var firstVar = 0
var secondVar = 0
var myFunx : MyFunx?
while secondVar < 100 {
print ("starting")
if myFunx == nil {
print ("making myFunx")
DispatchQueue.global().async {
myFunx = MyFunx()
}
} else {
myFunx!.addValues(a: firstVar, b: secondVar)
}
firstVar += 1
secondVar += 1
}
print ("myFunx = \(myFunx)")
print ("\(myFunx?.opsCount)")
print ("exiting")
Am working on a recording app from scratch and it just has the basics. Within my info.plist I do set Privacy - Microphone Usage Description
Still, I always want to check the "privacy permission" on the microphone because I know people can hit "No" by accident.
However, whatever I try, the app keeps running without waiting for the iOs permission alert to pop up and complete.
let mediaType = AVMediaType.audio
let mediaAuthorizationStatus = AVCaptureDevice.authorizationStatus(for: mediaType)
switch mediaAuthorizationStatus {
case .denied:
print (".denied")
case .authorized:
print ("authorized")
case .restricted:
print ("restricted")
case .notDetermined:
print("huh?")
let myQue = DispatchQueue(label: "get perm")
myQue.sync
{
AVCaptureDevice.requestAccess(for: .audio, completionHandler: { (granted: Bool) in
if granted {
} else {
}
})
}
default:
print ("not a clue")
}
Xcode updated yesterday, and am now at
Xcode Version 13.3 (13E113)
Since then, whenever I debug my app the the simulator, I get the message below. Am curious if I should be concerned.
If it makes a difference: Yes, I have an IBM keyboard attached via USB.
Also this does not happen when I debug the app on the iPhone itself.
2022-03-15 14:50:45.745237-0400 Hello World[48883:648134] [HardwareKeyboard] -[UIApplication getKeyboardDevicePropertiesForSenderID:shouldUpdate:usingSyntheticEvent:], failed to fetch device property for senderID (778835616971358211) use primary keyboard info instead.
I have a function in my UIView extension and I can call it both ways
This way:
func anchorSizePercent(to view: UIView, sFactor: CGSize) {
...
}
myHeader.anchorSizePercent(to: myView, sFactor: CGSize(width: 0.8, height: 0.2))
As well, I can call it without the to, such as:
func anchorSizePercent(view: UIView, sFactor: CGSize) {
...
}
myHeader.anchorSizePercent(view: myView, sFactor: CGSize(width: 0.8, height: 0.2))
May I ask what the difference is?