I am developing an iOS app where I am recording sound from the devices mic, saving it to a wav, then it needs to be accessed and played from a different view controller. As I understand, a FMOD::System object can only be defined in one view controller.
What would be the best way to access FMOD in more than one view controller?
I have tried using a Singleton class, however with objective-c's lack of class (non-instance) variables, I am not sure how declare the FMOD::System variable.
Has anyone successfully implemented what I am trying to do? Any help appreciated!
Thanks
I ended up making a singleton class and got it working.
If anyone would like help doing the same just ask.
Related
I've some simple sounds and I have multiple View Controllers and I wonder how to use sounds in every controller in my app. Should I create an extension, protocol, struct or something else? What would be the best OOP approach? There are plenty of tutorials but none of them shows how to efficiently use sounds in your app.
With your context, I suggest you to write something like SoundService, and declare it as a singleton. So every controller has the access to this service. The parameter for the service is something like sound file names.
This service will be used in the app, anytime the controller wants to play a sound, just call a method in the singleton. That will make your code looks better, and if you find any problem related to Sound, you know where to find the problem.
Im trying to follow this tutorial
The tutorial is a bit out dated because NIB files dont get used anymore like this with the xCode storyboards. So my question is how do I attach the webView instance variable to the Web View object? This is probably a really basic question hence im new to this.
Thanks
Oke i found out how to do it.
Here is a tutorial how to create a webView, the video starts at the whole delegate thing where i struggled with.
The video is still for the interface builder instead of the storyboard but the idea is very much the same.
Could anyone help me first when I can use AOP, and what is it exactly in an iphone programming.
I need to access to the app project source code and call some of the functions and be notified their views loaded from outside like a library.
I found these so far, but looks very complicated to follow. Some doesnt build or the source code removed.
https://github.com/ndcube/AOP-for-Objective-C
https://github.com/moszi/AOP-in-Objective-C
ACAspect on cocoadev
If you have a specific view in a view controller and want to be notified when it is loaded, you can register for a KVO notification when that instance variable (the outlet) changes.
You'll want to read up on Key Value Observing in Cocoa. There are several methods you will need to learn how to use.
Do a search on "Introduction to Key-Value Observing Programming Guide" in the XCode docs and read that section.
Make sure you balance each call to addObserver:forKeyPath:options:context: with a call to removeObserver:forKeyPath:, or your app may crash after the observing object is deallocated.
I'm new to iphone development. There's a lot of books on this topic available. But most of the beginner's guides are mostly concerned with Interface Builder usage and lack the information about existing built in XCode code templates or something that could help me in understanding MVC implementation in code. I found that it is possible to write working iOS program without ViewController at all. Well, it seems to me like that after working with the sample code called ViewTransitions.
So, the question is - why is that possible to avoid ViewController implementation in a program that has an interface with a button? If the answer is going to be too long, could you please recommend kind of tutorial or manual covering this topic.
Thanks in advance.
#user697562's answer is essentially correct: in the case of ViewTransitions, the role of the controller is played by the app delegate. The app does next to nothing -- it just switches betweeen two views to demonstrate several possible transition effects -- so a UIViewController isn't really needed there.
Notice that there's also nothing in ViewTransitions that you could really call a model object. If you're looking for a strong example of MVC, ViewTransitions isn't the best project to look at. Other sample projects, such as TheElements, give a better demonstration of MVC in action.
There is a concept called delegation. A concept which helps maintain MVC. It helps to keep the model separate from controllers. For eg: - UITableView/UICollectionView , which knows how to display the data and other ui stuff.
But it does not know which cell to display or what data to display at a particular index. And this is where delegation and the delegate object comes into place. UICollectionView handles all the view part whereas all the non view part is handled by the delgate object, which gives the required data for the view. This way a delegate(usually a separate view controller) acts as a data source and UICollectionView as a ui renderer.
in ViewTransitions, there IS an App Delegate, which is kind of your sole "controller". Even ViewTransitions has:
transition.delegate = self;
IOS is a bit different from some frameworks in that you aren't as "in control" of what is going on. It often uses a delegation model where you set your code as the delegate, but it (IOS) is in control. Still, you can write in MVC style, it's just your "C" isn't fully in charge.
I have an abstract class that initializes Finch to the global variable Finch *engine in the awakeFromNib method as follows:
engine = [[Finch alloc] init];
None of the abstract class's subclasses override the method. However, whenever I try my program, Finch prints "Finch: Could not open default OpenAL device." in the debugger. Why can't Finch get the default OpenAL device? As far as I can tell I'm doing everything as shown in their code example.
I just came across the same problem. For me, it was caused by instantiating a Finch object in more than one view controller. For some reason the second one seemed to cancel the first one out and I got that error message whenever I tried to play a sound.
To solve it, I simply created one Finch object in the App Delegate and now it's working perfectly throughout the whole app.
Hope this helps :)
Warning, if you are allocating multiple Finch classes:
In FISoundEngine, the dealloc method calls closeAudioDevice. This closes the OpenAL audio device.
And as you probably know, only one OpenAL device exists in your entire app!
So, that means you can only have one engine (and one factory) for your entire app,
or you will be closing the device in places where it should stay open.
Whether this is a design flaw, I don't know. I suggested that Finch be turned into
a singleton class, but my idea was rejected by the author.