Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.
Alright. Yes. I am making a stab in the dark. I'm just learning.

Yes I do see something wrong with the highlighted code. The ';'.

Here. I hightlight the error in red. The error is "Expected ';' before '{' Token".

Code:
//  Copyright 2011 __A.P.P.S__. All rights reserved.
//

#import "soundboard.h"
#import "Homestar_SFXViewController.h"


@implementation soundboard

@interface SomeClass {
    NSArray *Homestar_SFXViewController;
}

- (NSArray *)Homestar_SFXViewController;

[COLOR="Red"]-(IBAction)switchback:(id)sender {[/COLOR]
	Homestar_SFXViewController *second = [[Homestar_SFXViewController alloc] initWithNibName:nil bundle:nil];
	second.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
	[self presentModalViewController:second animated:YES];
}


Here are the next lines of codes with the same error as above.

Code:
//  Copyright 2011 __A.P.P.S__. All rights reserved.
//

#import "Homestar_SFXViewController.h"
#import "soundboard.h"
#import <AVFoundation/AVFoundation.h>

@implementation Homestar_SFXViewController


@interface SomeClass {
    NSArray *theAudio; // this should fix the compiler error
}

// If the filteredChildren method is public, add this declaration as well to prevent compiler warnings
- (NSArray *)theAudio;


[COLOR="red"]- (void)viewDidLoad {[/COLOR]
    NSString *path = [[NSBundle mainBundle] pathForResource:@"hrintro" ofType:@"wav"];
    theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
    theAudio.delegate = self;
	theAudio.numberOfLoops = 0;
	
    [theAudio play];
	
    [super viewDidLoad];
}


- (IBAction) myTap: (id) sender
{
    [theAudio stop];
}

- (void)dealloc {
    [theAudio release];
    [super dealloc];
}


-(IBAction)switchview:(id)sender {
	soundboard *second = [[soundboard alloc] initWithNibName:nil bundle:nil];
	second.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
	[self presentModalViewController:second animated:YES];
}

That is all the code. And I am going to learn all the basics after the forum.
 
You need to take a couple of steps back. The @interface section (in the .h) file is for declaring the publicly visible methods, instance variables and properties of the class. It cannot contain the implementation of those methods. This means you should see items like

Code:
-(void) myMethod;

but not

Code:
-(void) myMethod
{
NSLog(@"Boo");
}

The latter must be in the @implementation (in the .m file). You have the two wildly mixed and matched hence the errors.
 
I put the @implementation into the .m file, but I still get the same errors as before.
 
I put the @implementation into the .m file, but I still get the same errors as before.

Stop trying to learn to program via blind trial and error. It is extremely unlikely that this will work. You need to, at the very least, read and fully understand the Objective-C Language Guide. You are making fundamental errors that indicate a failure to grasp the core language concepts. Take a couple of days to study the theory then come back to the practical.
 
Alright. Thanks for all the help.
It was a valiant effort.
I'm going to read up on Objective-C.
 
Can you at least give me Example Project so I can see it work and maybe transfer it to my project?
 
I believe that true learning comes from testing not reading books.
And copy paste is testing. Though you'll need the basics first.

If you can't show me how the how can I learn?
 
I believe that true learning comes from testing not reading books.
And copy paste is testing.

Testing implies you know what is going to happen and are verifying that. If you are simply copying stuff and don't understand it you do not have a mental model of what the code is doing so the outcome is not something you can predict. This is no longer testing, rather uncontrolled and unpredictable experimentation. This is not something I have ever observed to be effective so I don't support it. If you are lucky someone else may.
 
I respect that, but I'm afraid that form of thinking isn't going to help me.
And this forum is to help me.
 
Though you'll need the basics first.
Which you admit you don't have yet. Come back when you have learned those and we might be able to provide some assistance with your experimentation, as long as you have specific issues you are trying to play around with.

And this forum is to help me.
True, and I believe we have given you plenty of help and advice already. But, without a solid understanding of the fundamentals, it may not seem like it.
 
I'd just like an Example Project. I gotta update my app soon.

See to me this reads as "I'd just like someone to write code specific to my needs for free that I can rip off and incorporate in my application and claim is my own work". However you look at it asking us to write you an example project that you freely admit you want to copy and paste into your application does not sound like learning…
 
*Sigh*

You've already gave me the code to write it. All I ask is that you can put in a project so I can find exactly where to put it.
 
I'd just like an Example Project.

Here are a couple dozen complete iOS example apps:
http://www.appsamuck.com/

One that uses sound is iDrum:
http://www.appsamuck.com/day21.html

I recommend starting with the 1st app, and not skipping the first 20 "days". I also recommend studying the source code, so you know what all the parts are, and how the Objective-C classes are actually written. For example, you're missing the @end statement in a lot of your posted code, or you've mistakenly stuck an @interface inside a different @implementation.

If you don't understand the Objective-C language, then you won't be able to understand what these apps do, nor be able to modify them to do something different. That seems to be the point that others have made: you're not even close to having the right syntax or structure for your Objective-C code.

You may have put together an app using copy/paste and some amount of luck, but you've now hit the wall. You need to understand the actual syntax and structure of Objective-C before you can get any further. The code you've posted so far is a complete mess, with pieces apparently pasted together in completely wrong ways. If it were an anatomy example, you've got the esophagus attached to the brain stem, and pieces of liver or spleen randomly attached as fingers and toes. I've been following the thread, and I have no idea how to even begin to rewrite it correctly for you, because I can't tell what kind of overall structure you want to have. I'm not saying I would rewrite it, just that if there's no discernable structure, it's not even possible to tell what the intent was.

EDIT:
Code dissection follows.

Code:
//  Copyright 2011 __A.P.P.S__. All rights reserved.
//

#import "Homestar_SFXViewController.h"
You haven't posted the code for "Homestar_SFXViewController.h".
I presume it contains the @interface for the Homestar_SFXViewController class.

It's impossible to fully understand what a class is or does without seeing its @interface. First, the @interface tells what the superclass is. Without that, we can't tell whether it's a view class, an NSObject, or something else. The superclass also tells what methods and instance variables are inherited, which is very important.

Second, @interface tells what the new class's instance variables and new methods are. Without that, it's impossible to tell what the implementation is referring to when it makes a reference to a variable name not defined in a function or method.

Code:
#import "soundboard.h"
You haven't posted the code for this header, either.

Code:
#import <AVFoundation/AVFoundation.h>

@implementation Homestar_SFXViewController
The @implementation line begins the implementation section for the Homestar_SFXViewController class.

Once an implementation section is started, you can't start any other @implementation or @interface sections until after the @end statement that terminates the first @implementation.

Code:
@interface SomeClass {
    NSArray *theAudio; // this should fix the compiler error
}

// If the filteredChildren method is public, add this declaration as well to prevent compiler warnings
- (NSArray *)theAudio;
I have no idea what the intent of this is. I see no filteredChildren method, so even the comment is indecipherable.

First, it's an @interface nested inside another class's @implementation, which is not allowed. Second, it's a class named with the uninformative SomeClass name. Third, it's not a subclass of NSObject or any other discernible class, which means it won't work with alloc, init, retain, release or any of the other methods it will need. It doesn't implement the NSObject protocol, either. Fourth, it has an instance variable declared as NSArray*, although that's completely the wrong type if you're expecting it to serve as the variable that holds the AVAudioPlayer created in viewDidLoad.

Finally, even if you were allowed to nest an @interface within an @implementation, you're missing the @end that terminates the @interface.

Code:
- (void)viewDidLoad {
    NSString *path = [[NSBundle mainBundle] pathForResource:@"hrintro" ofType:@"wav"];
    theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
    theAudio.delegate = self;
	theAudio.numberOfLoops = 0;
	
    [theAudio play];
	
    [super viewDidLoad];
}
I have no idea if this method is supposed to belong to SomeClass or to Homestar_SFXViewController.

If it's intended for SomeClass, then you've failed to start an @implementation for it. If it's for Homestar_SFXViewController, then we have no way of knowing what superclass it is, what protocol it implements, what instance variables it has, etc. because you haven't posted the @interface for it. That means we have no way of really understanding what it's doing (or attempting to do).

If you're expecting the variable named theAudio defined in SomeClass's @interface to somehow be merged into Homestar_SFXViewController, then you really have no understanding how classes are defined in Objective-C.

Code:
- (IBAction) myTap: (id) sender
{
    [theAudio stop];
}

- (void)dealloc {
    [theAudio release];
    [super dealloc];
}
Same things here: no idea which class these methods should belong to, no idea which instance variable theAudio is referring to, etc.

Code:
-(IBAction)switchview:(id)sender {
	soundboard *second = [[soundboard alloc] initWithNibName:nil bundle:nil];
	second.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
	[self presentModalViewController:second animated:YES];
}
You have some very similar code in your failed @implementation section for the soundboard class.

No idea if this similarity or near-duplication is intentional or not. No idea if the soundboard class or Homestar_SFXViewController are really subclasses of a suitable view controller superclass. I might guess that one of them is, and it's not soundboard, so no idea whether it makes any sense to present an instance of soundboard as a modal view controller.
 
Last edited:
Originally Posted by robbieduncan
However you look at it asking us to write you an example project that you freely admit you want to copy and paste into your application does not sound like learning…

Why don't you write comments of what part does what in the example project for this forum. That sounds like learning to me.

And I'm going to check out that link chown33.
 
Why don't you write comments of what part does what in the example project for this forum. That sounds like learning to me.

And I'm going to check out that link chown33.

There are plenty of fully commented example projects (that do other things) on the Apple website. Learning would be studying them and extrapolating the overall structure and methodology and applying that to your own code. As there are plenty such examples I see no need for an additional one. This seems like, once again, you simply want code that does exactly what you want written for you to steal.
 
I believe that true learning comes from testing not reading books.
And copy paste is testing. Though you'll need the basics first.

If you can't show me how the how can I learn?

If you don't read some of the the suggestions given to you already, how do you expect to gain the information required to backup your 'testing' (learning). You seem to be thinking half-ass-backwards.

I'm now convinced you are a troll. I just find it to difficult believe that you are serious.
 
I am reading the book you've been giving to me. I'm just saying that once you learn the basics true learning comes from testing.

I just want to learn how to stop background music when switching views, but since I haven't learned the basics I can only learn it by an Example Project.
 
I just want to learn how to stop background music when switching views, but since I haven't learned the basics I can only learn it by an Example Project.

You've already been shown the code that will stop the audio when switching views. It's this:
Code:
- (IBAction) myTap: (id) sender
{
    [theAudio stop];
}
The problem is, you don't know the fundamentals, so you can't make use of this code. You don't know how to make a class with an instance variable of the correct type for theAudio. If you did, you'd already know exactly what to do and where to put the code you've already been shown.

You don't need to learn how to stop audio in order to learn the fundamentals. Any program or project can be used to learn the fundamentals. Once you know the fundamentals, they will apply in all projects, and it should be trivial to figure out how to use the code that's already been shown to you.
 
I already told you I don't know. Why can't we get on with it and spend about 5 minutes writing exactly where to put each code? I'll read up on Objective-C after this is solved.
 
Why can't we get on with it and spend about 5 minutes writing exactly where to put each code?
Because we're not about to write all the code for you (even though xStep has given you a huge headstart!)

I'll read up on Objective-C after this is solved.
You should read up on Objective-C before you try to solve this problem. Because without an understanding of the basics, even if we were to give you an example project, you still may not be able to integrate the desired code into your own project.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.