I'm trying to incorporate AudioKit 4.0.3 (latest) into an existing iOS ViewController that's written in Objective C. I am having trouble initializing and using the AKFrequencyTracker class, even though other classes work fine (e.g. AKOscillator and AKMicrophone).
I added the following code to the ViewController viewDidLoad method in the Objective C example that came with it:
AKMicrophone *mic;
mic = [[AKMicrophone alloc] init];
AKFrequencyTracker *tracker;
tracker = [[AKFrequencyTracker alloc] init:mic hopSize:512.0 peakCount:20.0];
But I see an "No visible #interface for 'AKFrequencyTracker'" error in Xcode next to the last line.
It doesn't appear there are any init methods for AKFrequencyTracker. Any help would be greatly appreciated!
Due to a change with Swift 4 we need to explicitly add #objc to the init methods and forgot to do so with AKFrequencyTracker. I just fixed it in this commit:
https://github.com/AudioKit/AudioKit/commit/e9328d4aa8d76d0cae31eeb33b232abebd571d6e
Related
I've used Nuance SpeechKit for some months using Objective-C. Now I'm coding in Swift - except for the class where I instantiate the SKRecognizer and SpeechKit has stopped working.
When I try to initialise the SKRecognizer object I get the following error:NMSP_ERROR] check status Error: 696e6974 init -> line: 485 makeFullPathname
Is it possible that it's because I'm using swift in the rest of the project?
How can I prevent screen lock only when using Navigation?
Waze has the option to do that, how can I do this in my App?
Use this:
Objective-C:
[[UIApplication sharedApplication] setIdleTimerDisabled: YES];
Swift (legacy):
UIApplication.sharedApplication().idleTimerDisabled = true
Swift 3 and above:
UIApplication.shared.isIdleTimerDisabled = true
Make sure to import UIKit.
Here is the link to the documentation from developer.apple.com.
For Swift 3.0 here are two options depending on where you want to invoke the code:
Inside AppDelegate.swift:
application.idleTimerDisabled = true
Outside AppDelegate.swift:
UIApplication.shared().isIdleTimerDisabled = true
Swift 4
in AppDelegate.swift file, add the following line inside application function:
application.isIdleTimerDisabled = true
You can use my little lib Insomnia (Swift 3, iOS 9+) - another nice feature is that you can prevent from sleeping only when charging.
The idleTimerDisabled soultion is okay but you have to remember to set it to false afterwards.
If you have more advanced case you can use our small project: ScreenSleepManager or if it's just about particular ViewControllers - use Insomnia as pointed earlier. Manual dealing with idleTimerDisabled almost always caused me some issues (like forgot to re-set to false or handle multiple (nested) modules trying to set it).
I am totally new to iOS development, and I decided to start directly with the new Swift programming language. But some Objective C knowledge is needed though, so this is a very basic question!
I am trying to use the FreeStreamer library, to play a shoutcast stream in my iOS app. I followed the basic steps (copied among others the needed file in my Xcode project) but how can I access to the FSAudioStream from my Swift class?
I tried this:
import UIKit
class FirstViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let test = FSAudioStream
}
// ...
}
But the FSAudioStream class is not found, which doesn't surprise me. Should I add an extra import to my file? In that case, which one?
Ok, I found the solution from this Apple Developer page on mixing Swift and Objective C.
But there was something important: when setting the "Objective-C Bridging header" in the "Swift Compiler - Code Generation" section of the project, the path has to be set generally which in turns set value for both the "Debug" and "Release" keys.
So I set the "Swift Compiler - Code Generation" parameter to MyProject/MyProject-Header.h.
And in the MyProject/MyProject-Header.h file I added this:
#import "FSAudioStream.h"
And then there is nothing to import in the Swift file.
Problem solved!
I'm developing iOS app that handles .csv file with CHCSVParser in swift.
in Objective-C, the initialization code goes like this.
CHCSVParser *p = [[CHCSVParser alloc] initWithContentsOfCSVFile:[inputFileURL path]
so in swift, I think it goes like
var p = CHCSVParser()
p.initWithContentsOfCSVFile(path)
but this code leads error "CHCSVParser does not have a member named 'initWithContentsOfCSVFile'".
BridgingHeader file works fine.
func parserDidBeginDocument(parser: CHCSVParser)
this delegation method successfully calld after p.parse() .
Does anyone please help me? What should I do?
Any advice appreciated. Thanks in advance.
Swift does an automatic conversion of Objective-C constructors and removes "initWith". So in Swift, it is like this:
var p = CHCSVParser(contentsOfCSVURL: path)
In cases such as this, I recommend just typing the first part:
var p = CHCSVParser(
an then taking a look at what Xcode autocomplete suggests.
In my app I have a view controller written in Swift. I imported it in to app delegate which is written in objective c. I try to create an object of the swift view controller like this
ListAllSongsViewController *songListVC = [[ListAllSongsViewController alloc]initWithNibName:#"ListAllSongsViewController" bundle:nil];
The ListAllSongsViewController is written in swift. The project compile without any issue but when executing the above line the app crashes & stops at init method of ListAllSongsViewController
There is nothing in the log, it just stops. Zombie & All exception break points are enabled.
P.S. It only crashes in device (iOS 7.1), but works fine in simulator
Update :
Getting the same issue even if I use the default swift initialiser
ListAllSongsViewController(nibName: "ListAllSongsViewController", bundle: nil)
Usually occurs when you passed a wrong nibName. Considering it crashes only in device, I think you've made a mistake about the case of the string ListAllSongs, because the Mac/Simulator's file system is case insensitive while the device is not.