NSSound not working properly - objective-c

I am using Cocoa on Mac 10.6. I am trying to have a metronome click out the time but when I run the code only the first two sounds are played then it is quiet till the end when a sound plays again. If I replace the [player play] statements with NSBeep() it works fine. Any suggestions?
#import <Cocoa/Cocoa.h>
#interface Metronome : NSObject {
NSInteger timeSig;
NSInteger noteValue;
NSInteger bpm;
NSUInteger beatNumber;
CGFloat duration;
NSSound *tickPlayer;
NSSound *tockPlayer;
}
#property(readwrite) NSInteger timeSig;
#property(readwrite) NSInteger noteValue;
#property(readwrite) NSInteger bpm;
#property(readwrite) float duration;
#property(readwrite) NSUInteger beatNumber;
-(id)init;
-(id)initWithTimeSig:(NSInteger)ts andNoteValue:(NSInteger)nv andBpm:(NSInteger)bp;
-(void)BeginMetronome;
-(void)PlaySound;
#end
#import "Metronome.h"
#define defaultBpm 80
#define defaultTimeSig 4
#define defaultNoteValue 4
#implementation Metronome
#synthesize timeSig, noteValue, duration, bpm, beatNumber;
-(id)init{
return [self initWithTimeSig:defaultTimeSig andNoteValue:defaultNoteValue andBpm:defaultBpm];
}
-(id)initWithTimeSig:(NSInteger)ts andNoteValue:(NSInteger)nv andBpm:(NSInteger)bp {
[super init];
if(self){
self.timeSig = ts;
self.noteValue = nv;
self.bpm = bp;
self.duration = 60.0/bpm;
tickPlayer = [NSSound soundNamed:#"Hat1"];
tockPlayer = [NSSound soundNamed:#"Hat2"];
self.beatNumber = 1;
}
return self;
}
-(void)BeginMetronome{
BOOL continuePlaying = YES;
NSInteger iter=0;
while (continuePlaying){
if(iter > 12){
continuePlaying = FALSE;
}
iter++;
[self PlaySound];
NSDate *curtainTime = [[NSDate alloc] initWithTimeIntervalSinceNow:self.duration];
NSDate *currentTime = [[NSDate alloc] init];
while (continuePlaying && ([currentTime compare:curtainTime] != NSOrderedDescending)) {
// if ([soundPlayerThread isCancelled] == YES) {
// continuePlaying = NO;
//}
//[NSThread sleepForTimeInterval:0.01];
sleep(.01);
//[tickPlayer stop];
//[tockPlayer stop];
[currentTime release];
currentTime = [[NSDate alloc] init];
}
[curtainTime release];
[currentTime release];
}
}
- (void)PlaySound { //***********Problem in this loop
if ([tickPlayer isPlaying])
[tickPlayer stop];
if ([tockPlayer isPlaying])
[tockPlayer stop];
if (beatNumber == 1) {
[tockPlayer play];
}
else if (beatNumber == 2){
[tickPlayer play];
}
else if (beatNumber == self.timeSig) {
beatNumber = 0;
[tickPlayer play];
}
else{
//[tickPlayer stop];
[tickPlayer play];
NSBeep();
}
beatNumber++;
//NSLog(#" %d ", beatNumber);
// NSBeep();
}
#end

I believe your use of sleep() is blocking the playing of NSSound. That's a very sloppy way to do this, instead use a timer like so:
static NSInteger iter;
- (void) beginMetronome {
iter = 0;
NSTimer *timer = [NSTimer timerWithTimeInterval:self.duration target:self selector:#selector(continueMetronome:) userInfo:nil repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];
[timer fire];
}
- (void) continueMetronome:(NSTimer *)theTimer {
[self PlaySound];
if (++iter > 12) {
[theTimer invalidate];
}
}
Also, you must retain the sounds that you plan to use in your init method.
tickPlayer = [[NSSound soundNamed:#"Hat1"] retain];
tockPlayer = [[NSSound soundNamed:#"Hat2"] retain];
And Cocoa methods should start with a lowercase letter like I've written them. I'm not too sure how metronomes are supposed to work, so you may have to change the value of 12 to something else.

Related

Trying to make SplashScene (Cocos2d) form the book of Pablo Ruiz, and it doesnt work

I add this scene to project and run it at ProjectRunDelegate
it fell when method cFadeAndShow starts
Can anybody tell me whats the problem?
im using xCode 3.2.6
and cocos2d 1.0.1
Or maybe someone already has working splash scene to show some company's logos on starts of game
Thanks
#import "SplashScene.h"
#implementation SplashScene
-(id) init {
if ( (self = [super init])) {
[self addChild:[SplashLayer node]];
}
return self;
}
-(void)dealloc{
[super dealloc];
}
#end
#implementation SplashLayer
-(id) init {
if ( (self = [super init])) {
self.isTouchEnabled = YES;
NSMutableArray * splashImages = [[NSMutableArray alloc] init];
for (int i =1; i<=2; i++) {
CCSprite *splashImage = [CCSprite spriteWithFile:[NSString stringWithFormat:#"splash%d.png",i]];
if (splashImage == nil) {
CCLOG(#"splashImage is nil");
}
[splashImage setPosition:ccp(240,160)];
[self addChild:splashImage];
if (i!=1)
[splashImage setOpacity:0];
[splashImages addObject:splashImage];
}
[self fadeAndShow:splashImages];
}
return self;
}
-(void) fadeAndShow:(NSMutableArray *) images{ // add the meehods
if ([images count]<=1) {
[images release];
[[CCDirector sharedDirector]replaceScene:[GameScene scene]];
}
else {
CCSprite *actual = (CCSprite *)[images objectAtIndex:0];
[images removeObjectAtIndex:0];
CCSprite * next = (CCSprite *)[images objectAtIndex:0];
[actual runAction:[CCSequence actions:[CCDelayTime actionWithDuration:2], [CCFadeOut actionWithDuration:1],
[CCCallFuncN actionWithTarget:self selector:#selector(remove:)],nil]];
[next runAction:[CCSequence actions:[CCDelayTime actionWithDuration:2], [CCFadeIn actionWithDuration:1],
[CCDelayTime actionWithDuration:2],
[CCCallFuncND actionWithTarget:self selector:#selector(cFadeAndShow:data:) data:images],nil]];
}
}
-(void) cFadeAndShow:(id)sender dara:(void*)data{
NSMutableArray * images = (NSMutableArray *) data;
[self fadeAndShow:images];
}
-(void)remove:(CCSprite *)s{
[s.parent removeChild:s cleanup:YES];
}
-(void)dealloc{
[super dealloc];
}
#end
Here's an answer:
[[CCDirector sharedDirector] replaceScene: [CCTransitionZoomFlipAngular
transitionWithDuration:2
scene:[GameScene node]
orientation:kOrientationLeftOver]];

How to fix: Incomplete Implementation

How can I fix the problem of Incomplete Implementation?
View of Controller.m :
#import "Quiz_GameViewController.h"
#implementation Quiz_GameViewController
#synthesize theQuestion, timer, theScore, theLives, answerOne, answerTwo, answerThree, answerFour, theQuiz
;
-(void)askQuestion
{
// Unhide all the answer buttons.
[answerOne setHidden:NO];
[answerTwo setHidden:NO];
[answerThree setHidden:NO];
[answerFour setHidden:NO];
// Set the game to a "live" question (for timer purposes)
questionLive = YES;
// Set the time for the timer
time = 8.0;
// Go to the next question
questionNumber = questionNumber + 1;
// We get the question from the questionNumber * the row that we look up in the array.
NSInteger row = 0;
if(questionNumber == 1)
{
row = questionNumber - 1;
}
else
{
row = ((questionNumber - 1) * 6);
}
// Set the question string, and set the buttons the the answers
NSString *selected = [theQuiz objectAtIndex:row];
NSString *activeQuestion = [[NSString alloc] initWithFormat:#"Question: %#", selected];
[answerOne setTitle:[theQuiz objectAtIndex:row+1] forState:UIControlStateNormal];
[answerTwo setTitle:[theQuiz objectAtIndex:row+2] forState:UIControlStateNormal];
[answerThree setTitle:[theQuiz objectAtIndex:row+3] forState:UIControlStateNormal];
[answerFour setTitle:[theQuiz objectAtIndex:row+4] forState:UIControlStateNormal];
rightAnswer = [[theQuiz objectAtIndex:row+5] intValue];
// Set theQuestion label to the active question
theQuestion.text = activeQuestion;
// Start the timer for the countdown
timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:#selector(countDown) userInfo:nil repeats:YES];
[selected release];
[activeQuestion release];
}
-(void)updateScore
{
// If the score is being updated, the question is not live
questionLive = NO;
[timer invalidate];
// Hide the answers from the previous question
[answerOne setHidden:YES];
[answerTwo setHidden:YES];
[answerThree setHidden:YES];
[answerFour setHidden:YES];
NSString *scoreUpdate = [[NSString alloc] initWithFormat:#"Score: %d", myScore];
theScore.text = scoreUpdate;
[scoreUpdate release];
// END THE GAME.
NSInteger endOfQuiz = [theQuiz count];
if((((questionNumber - 1) * 6) + 6) == endOfQuiz)
{
// Game is over.
if(myScore > 0)
{
NSString *finishingStatement = [[NSString alloc] initWithFormat:#"Game Over!\nNice Game \nYou scored %i!", myScore];
theQuestion.text = finishingStatement;
[finishingStatement release];
}
else
{
NSString *finishingStatement = [[NSString alloc] initWithFormat:#"Game Over!\n You're terrible! \nYou scored %i.", myScore];
theQuestion.text = finishingStatement;
[finishingStatement release];
}
theLives.text = #"";
// Make button 1 appear as a reset game button
restartGame = YES;
[answerOne setHidden:NO];
[answerOne setTitle:#"Restart game!" forState:UIControlStateNormal];
}
else
{
// Give a short rest between questions
time = 3.0;
// Initialize the timer
timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:#selector(countDown) userInfo:nil repeats:YES];
}
}
-(void)countDown
{
// Question live counter
if(questionLive==YES)
{
time = time - 1;
theLives.text = [NSString stringWithFormat:#"Time remaining: %i!", time];
if(time == 0)
{
// Loser!
questionLive = NO;
theQuestion.text = #"HAHA now you lost alot of points!";
myScore = myScore - 1000;
[timer invalidate];
[self updateScore];
}
}
// In-between Question counter
else
{
time = time - 1;
theLives.text = [NSString stringWithFormat:#"Next question coming in...%i!", time];
if(time == 0)
{
[timer invalidate];
theLives.text = #"";
[self askQuestion];
}
}
if(time < 0)
{
[timer invalidate];
}
}
- (IBAction)buttonOne
{
if(questionNumber == 0){
// This means that we are at the startup-state
// We need to make the other buttons visible, and start the game.
[answerTwo setHidden:NO];
[answerThree setHidden:NO];
[answerFour setHidden:NO];
[self askQuestion];
}
else
{
NSInteger theAnswerValue = 1;
[self checkAnswer:(int)theAnswerValue];
if(restartGame==YES)
{
// Create a restart game function.
}
}
}
- (IBAction)buttonTwo
{
NSInteger theAnswerValue = 2;
[self checkAnswer:(int)theAnswerValue];
}
- (IBAction)buttonThree
{
NSInteger theAnswerValue = 3;
[self checkAnswer:(int)theAnswerValue];
}
- (IBAction)buttonFour
{
NSInteger theAnswerValue = 4;
[self checkAnswer:(int)theAnswerValue];
}
// Check for the answer (this is not written right, but it runs)
-(void)checkAnswer:(int)theAnswerValue
{
if(rightAnswer == theAnswerValue)
{
theQuestion.text = #"Daaamn";
myScore = myScore + 50;
}
else
{
theQuestion.text = #"hahaha!";
myScore = myScore - 50;
}
[self updateScore];
}
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
questionLive = NO;
restartGame = NO;
theQuestion.text = #"Think you can do it?";
theScore.text = #"Score:0";
theLives.text = #"";
questionNumber = 0;
myScore = 0;
myLives = 0;
[answerOne setTitle:#"I think i can!" forState:UIControlStateNormal];
[answerTwo setHidden:YES];
[answerThree setHidden:YES];
[answerFour setHidden:YES];
[self loadQuiz];
}
-(void)loadQuiz
{
// This is our forced-loaded array of quiz questions.
// FORMAT IS IMPORTANT!!!!
// 1: Question, 2 3 4 5: Answers 1-4 respectively, 6: The right answer
// THIS IS A TERRIBLE WAY TO DO THIS. I will figure out how to do nested arrays to make this better.
NSArray *quizArray = [[NSArray alloc] initWithObjects:#"Who is the president in USA?",#"Me",#"Obama",#"George Bush",#"Justin Bieber",#"2",
#"Capital in Norway?", #"Bergen", #"Trondheim", #"Oslo", #"Bærum", #"3",
#"The right answer is 3!", #"41", #"24", #"3", #"9", #"1",
#"Do I have a cat?", #"Yes", #"No", #"No, you have a dog", #"No, you have a flying hamster", #"4",
#"Baba", #"Daba jaba?", #"Laba daba haba?", #"Saba daba gaba?", #"Haba haba?", #"4",
nil];
self.theQuiz = quizArray;
[quizArray release];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
// Release anything that's not essential, such as cached data
}
- (void)dealloc {
[theQuestion release];
[theScore release];
[theLives release];
[answerOne release];
[answerTwo release];
[answerThree release];
[answerFour release];
[theQuiz release];
[timer release];
[super dealloc];
}
#end
I'am new here and this is an example script from the internet...I use it to learn the language Objective-C and Cocoa...ViewController.h :
#import <UIKit/UIKit.h>
#interface Quiz_GameViewController : UIViewController {
IBOutlet UILabel *theQuestion;
IBOutlet UILabel *theScore;
IBOutlet UILabel *theLives;
IBOutlet UIButton *answerOne;
IBOutlet UIButton *answerTwo;
IBOutlet UIButton *answerThree;
IBOutlet UIButton *answerFour;
NSInteger myScore;
NSInteger myLives;
NSInteger questionNumber;
NSInteger rightAnswer;
NSInteger time;
NSArray *theQuiz;
NSTimer *timer;
BOOL questionLive;
BOOL restartGame;
}
#property (retain, nonatomic) UILabel *theQuestion;
#property (retain, nonatomic) UILabel *theScore;
#property (retain, nonatomic) UILabel *theLives;
#property (retain, nonatomic) UIButton *answerOne;
#property (retain, nonatomic) UIButton *answerTwo;
#property (retain, nonatomic) UIButton *answerThree;
#property (retain, nonatomic) UIButton *answerFour;
#property (retain, nonatomic) NSArray *theQuiz;
#property (retain, nonatomic) NSTimer *timer;
-(IBAction)buttonOne;
-(IBAction)buttonTwo;
-(IBAction)buttonThree;
-(IBAction)buttonFour;
-(void)checkAnswer;
-(void)askQuestion;
-(void)updateScore;
-(void)loadQuiz;
-(void)countDown;
#end
In your headerfile, you have declared the method -(void)checkAnswer, while in the .m file you have declared it -(void)checkAnswer:(int)theAnswerValue.
This means that your .m file is looking for a method -(void)checkAnswer, which does not exist, and it yields an Incomplete implementation warning. Simply change your declaration in the .h file to - (void)checkAnswer:(int)theAnswerValue, and you'll be fine.
See in .h you have (method with no parameters):
-(void)checkAnswer;
and in .m you have (method with one int parameter):
-(void)checkAnswer:(int)theAnswerValue
Incomplete Implementation means you declared something in .h but didn't implement that in .m.
The signature of checkAnswer is different in you .h and .m
in Quiz_GameViewController.h:
-(void)checkAnswer;
in Quiz_GameViewController.m
-(void)checkAnswer:(int)theAnswerValue
FIX : Change the Quiz_GameViewController.h to:
- (void)checkAnswer:(int)theAnswerValue,

Check if an animation image is in an image view at a given time

I have an image view that has two animation images, occuring in 1-second intervals. I want to run some methods when my image view is displaying one of those two images
I already tried doing:
if(self.imageViewThatPerformsAnimation.image == [UIImage imageNamed: #"someImage"])
[self doSomeMethod];
but when I tried this and ran it, [self doSomeMethod]; always ran, and not just when the image view was displaying that one image.
I'm thinking about having a timer that changes a boolean value every one second then saying
if (booleanValue==YES)
[self doSomeMethod]
It's just that I feel there may be a better way.
If you wanted to use a NSTimer, it might look like:
#interface MyViewController ()
{
NSTimer *_timer;
NSArray *_images;
NSInteger _currentImageIndex;
}
#end
#implementation MyViewController
#synthesize imageview = _imageview;
- (void)viewDidLoad
{
[super viewDidLoad];
_images = [NSArray arrayWithObjects:
[UIImage imageNamed:#"imgres-1.jpg"],
[UIImage imageNamed:#"imgres-2.jpg"],
[UIImage imageNamed:#"imgres-3.jpg"],
[UIImage imageNamed:#"imgres-4.jpg"],
nil];
_currentImageIndex = -1;
[self changeImage];
// Do any additional setup after loading the view.
}
- (void)changeImage
{
_currentImageIndex++;
if (_currentImageIndex >= [_images count])
_currentImageIndex = 0;
self.imageview.image = [_images objectAtIndex:_currentImageIndex];
if (_currentImageIndex == 0)
[self doSomething];
}
- (void)startTimer
{
if (_timer) {
[_timer invalidate];
_timer = nil;
}
_timer = [NSTimer timerWithTimeInterval:1.0
target:self
selector:#selector(changeImage)
userInfo:nil
repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:_timer forMode:NSDefaultRunLoopMode];
}
- (void)stopTimer
{
[_timer invalidate];
_timer = nil;
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self startTimer];
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
[self stopTimer];
}

NSManagedObjectContext outside the PersistentDocument

I've created a Document Application for Mac OSX to work with CoreDataModel.
Now I'm trying to programmatically save a value in the coredata when a button is clicked.
I'm able to save a value when the app start:
- (void)windowControllerDidLoadNib:(NSWindowController *)aController
{
[super windowControllerDidLoadNib:aController];
NSManagedObjcetContext *moc = [self managedObjectContext];
NSSet *session = [moc fetchObjectsForEntityName:#"Sessions" withPredicate:nil];
NSLog(#"%d", (int)[session count]);
NSManagedObject *obj = [NSEntityDescription insertNewObjectForEntityForName:#"Sessions"
inManagedObjectContext:moc];
[obj setValue:#"TEST" forKey:#"name"];
[obj setValue:[NSDate dateWithTimeIntervalSinceReferenceDate:112700] forKey:#"start"];
[obj setValue:[NSDate dateWithTimeIntervalSinceReferenceDate:118700] forKey:#"stop"];
}
but I want to save a value of a counter inside a NSObject. So I've tried to create a function in the PersistentDocument like the previous passing a value, but the count of the coredata elements is 0, so I think that is not referencing to the correct Entity.
Can anyone explain me how to do that or how this can works?
Thanks
Ale
EDIT:
I'll try to be more clear.
I've a chrono counter with START and STOP button. I want to save the value of the timer, when is stopped, in the coredata using another button SAVE. The managing of the counter is in an NSObject CounterObject.
How can I do it? Now I'm able to write in the core data only from the PersistentDocument caling a function from windowControllerDidLoadNib. I want to call a function that write in the coredata my counter value, but if I call the function in the PersistentDocument from the CounterObject the log that I've inserted show 0 elements instead of 4. So it's not correctly passed.
Here is the code:
// Document
#import "Document.h"
#import "NSManagedObjectContext.h"
#implementation Document
- (id)init
{
self = [super init];
if (self) {
}
return self;
}
- (NSString *)windowNibName
{
// Override returning the nib file name of the document
// If you need to use a subclass of NSWindowController or if your document supports multiple NSWindowControllers, you should remove this method and override -makeWindowControllers instead.
return #"Document";
}
- (void)windowControllerDidLoadNib:(NSWindowController *)aController
{
[super windowControllerDidLoadNib:aController];
[self saveTimeMOC:[NSDate dateWithString:#"11:23:34"]];
}
-(IBAction)saveTimeMOC:(NSDate *)time {
NSManagedObjectContext *moc = [self managedObjectContext];
NSSet *session = [moc fetchObjectsForEntityName:#"Sessions" withPredicate:nil];
NSLog(#"%d", (int)[session count]);
NSManagedObject *obj = [NSEntityDescription insertNewObjectForEntityForName:#"Sessions"
inManagedObjectContext:moc];
[obj setValue:#"TEST" forKey:#"name"];
[obj setValue:time forKey:#"start"];
[obj setValue:[NSDate dateWithTimeIntervalSinceReferenceDate:118700] forKey:#"stop"];
}
+ (BOOL)autosavesInPlace
{
return YES;
}
#end
// CounterObject
#import "CounterObject.h"
#import "Document.h"
#implementation CounterObject
#synthesize contText, startButton, stopButton;
-(id)init {
self = [super init];
if (self) {
}
return self;
}
- (IBAction)startContatore:(id)sender {
stopButton.title = #"Stop";
[stopButton setEnabled:YES];
[startButton setEnabled:NO];
timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:#selector(gestioneTimer) userInfo:nil repeats:YES];
}
- (IBAction)stopContatore:(id)sender {
if (timer != nil) {
[timer invalidate];
timer = nil;
}
if (stopButton.title != #"Reset") {
[startButton setEnabled:YES];
stopButton.title = #"Reset";
startButton.title = #"Continue";
} else if (stopButton.title == #"Reset") {
stopButton.title = #"Stop";
[stopButton setEnabled:NO];
startButton.title = #"Start";
timerCont = 0;
contText.stringValue = [NSString stringWithFormat:#"00:00"];
}
}
- (void)gestioneTimer {
timerCont += 1;
int minutes = floor(timerCont/60);
int seconds = trunc(timerCont - minutes * 60);
contText.stringValue = [NSString stringWithFormat:#"%02i:%02i", minutes, seconds];
}
- (IBAction)saveTime:(id)sender {
Document *moc = [[Document alloc] init];
[moc saveTimeMOC:[NSDate dateWithString:#"13:45:22"]];
}
If you want to add an Object to core data, you can do this :
- (void)windowControllerDidLoadNib:(NSWindowController *)aController
{
[super windowControllerDidLoadNib:aController];
NSManagedObjcetContext *moc = [self managedObjectContext];
// But be sure that [self managedObjectContext] is the correct one; you can do this to see if //it's not a null value : NSLog(#"%#",[self managedObjectContext]);
NSManagedObject *obj = [NSEntityDescription insertNewObjectForEntityForName:#"Sessions"
inManagedObjectContext:moc];
[obj setValue:#"TEST" forKey:#"name"];
[obj setValue:[NSDate dateWithTimeIntervalSinceReferenceDate:112700] forKey:#"start"];
[obj setValue:[NSDate dateWithTimeIntervalSinceReferenceDate:118700] forKey:#"stop"];
}
And a request for Core Data is :
-(voi)testRequestCoreData {
NSError *error =nil;
NSFetchRequest *fetchRequest = [[[NSFetchRequest alloc] init]autorelease];
NSEntityDescription *entity = [NSEntityDescription
entityForName:#"Sessions" inManagedObjectContext:moc];
[fetchRequest setEntity:entity];
NSArray *fetchedObjects = [context executeFetchRequest:fetchRequest error:&error];
....
}

NSArray causes EXC_BAD_ACCESS

I declare an NSArray in one class like this:
.h
#interface HTTP : NSObject {
NSArray *listOfProfiles;
}
#property (nonatomic, retain) NSArray *listOfProfiles;
.m
-(id) init {
if ((self = [super init])) {
listOfProfiles = [[NSArray alloc] init];
}
return self;
}
-(void) someMethod {
...
case GET_LIST_OF_PROFILES:
listOfProfiles = [result componentsSeparatedByString:#"^-^"];
NSLog(#"first break: %#",[listOfProfiles objectAtIndex:0]);
break;
...
}
I can access it here just fine, then when I try to access it in another class after creating an object I receive the error EXC_BAD_ACCESS and the debugger goes to main.m:
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
http = [[HTTP alloc] init];
[http createProfileArray];
profileListDelay = [[NSTimer alloc] init];
profileListDelay = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:#selector(profileListSelector) userInfo:nil repeats:YES];
}
- (void) profileListSelector
{
if (http.activityDone)
{
// http.listofprofiles mem leak?
for (int i = 0; i < http.listOfProfiles.count; i++)
{
NSLog(#"%#",[http.listOfProfiles objectAtIndex:i]);
}
[profileListDelay invalidate];
profileListDelay = nil;
}
}
I'm thinking it's a memory issue maybe, but I could be completely wrong.
It is a memory issue
It is in someMethod
-(void) someMethod {
...
case GET_LIST_OF_PROFILES:
listOfProfiles = [result componentsSeparatedByString:#"^-^"];
NSLog(#"first break: %#",[listOfProfiles objectAtIndex:0]);
break;
...
}
componentsSeparatedByString: returns an autoreleased object
Since you declared the array as a retain property, you should update it like so:
self.listOfProfiles = [result componentsSeparatedByString:#"^-^"];