XCode- Need Help With Errors (Expected ; and Expected Statement) - xcode

.m coding:
-(void)viewDidLoad {
NSString *path = [[NSBundle mainBundle] pathForResource:#"MathMusic2" ofType:#"wav"];
self.theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL]
autorelease]; //error: expected ';' before 'autorelease' and // error: expected statement before ']' token
theAudio.delegate = self;
[theAudio play];
theAudio.numberOfLoops = -1;
}
related warnings:
warning: property 'theAudio' requires
method '-theAudio' to be defined - use
#synthesize, #dynamic or provide a
method implementation
warning: property 'theAudio' requires
the method 'setTheAudio:' to be
defined - use #synthesize, #dynamic or
provide a method implementation
tell me if you need .h coding. But there are no errors there.

The two errors are because you are missing an opening [ in the previous line:
self.theAudio = [[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL] autorelease];
The warnings are because you forgot #synthesize theAudio; in your #implementation (or forgot to write custom getter and setter methods). At runtime, you'll get an unknown selector exception if you don't fix that.

It was me in the previous question, my code was erroneous, this should correct it:
self.theAudio = [[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL] autorelease];
To this error:
warning: property 'theAudio' requires
method '-theAudio' to be defined - use
#synthesize, #dynamic or provide a
method implementation
Do you know what a property is? If not, look at this short tutorial. I actually provided the code in your previous question, but you have to know where to put it.

Related

CoreBluetooth[WARNING] has no restore identifier but the delegate implements

I'm using the CoreBluetooth but I got this warning message in the output.
CoreBluetooth[WARNING] has no restore identifier but the delegate implements the centralManager:willRestoreState: method. Restoring will not be supported!
I'm using this code:
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:NO], CBCentralManagerOptionShowPowerAlertKey, nil];
myCentralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil options:options];
I don't know what's wrong.
Thanks.
This is in regards to CoreBluetooth's save/restore optional feature, see "Opt In to State Preservation and Restoration" part of the documentation for more details.
What looks to be happening is that you are implementing the right delegate method to use this feature but you are not providing a restoration identifier in your call to initialize the CBCentralManager.
There are two options to resolve the warning:
If you want to use this feature you should provide a string identifier that represents the central or peripheral manager to CBCentralManager like so:
myCentralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil
options:#{ CBCentralManagerOptionRestoreIdentifierKey:
#"myCentralManagerIdentifier" }];
If you don't want to use this feature then remove the centralManager:willRestoreState: method from your delegate.
Doing either one should resolve your warning.

Use of Undeclared Identifier error in CoreLocation

I don't under why the error: Use of undeclared identifier 'KCLDistanceFilterNone' and 'kCLLocationAccuracyHundredMeters' keeps coming up for my CoreLocation.m folder. There are also many more errors even when I deleted the ";" from select lines. Can someone please help?
#import "CoreLocation.h"
#implementation CoreLocation : NSObject
- (NSString *)deviceLocation {
NSString *theLocation = [NSString stringWithFormat:#"latitude: %f longitude: %f", locationManager.location.coordinate.latitude, locationManager.location.coordinate.longitude];
return theLocation;
}
- (void)viewDidLoad
{
locationManager = [[locationManager alloc] init];
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters;
[locationManager startUpdatingLocation];
}
#end
Also, what would I put in my CoreLocation.m folder to complement this and complete the location services for my application?
A couple of thoughts:
Have you included the CoreLocation.framework in the list of linked libraries/frameworks?
Have you done the import of CoreLocation.framework header?
#import <CoreLocation/CoreLocation.h>
I wouldn't have thought that CoreLocation is a good name for your class, because of the confusion between the above line, and your line that says:
#import "CoreLocation.h"
It should work (having both of those lines), but it seems unnecessarily confusing (and risks problems associated with #import's feature that automatically prevents loading the same .h file twice).
I'd suggest give your custom CoreLocation class (a) a unique name that doesn't risk confusion with the existing headers; and (b) a more meaningful name that indicates what it's doing (e.g. CoreLocationUtilities or AppCoreLocationManager or whatever).
Your alloc/init method line references a variable name:
locationManager = [[locationManager alloc] init];
It should presumably reference a class name, e.g.:
locationManager = [[CLLocationManager alloc] init];
It makes me wonder how you defined the locationManager instance variable if you didn't get an error on that line.
Unrelated to your issue, I'm confused by your reference of your custom CoreLocation class being a NSObject subclass, but then having a viewDidLoad method, which is typically a view controller method. That seems to only further muddy the waters.

Xcode Core-Data to-many relationship: addObject method error

I have the following core-data structure:
I am trying to add Vocabulary objects to the Group class.
My attempts at doing this with the [Group addObject: VocabularyObject] method have
come to no avail.
AppDelegate *delegate = [[AppDelegate alloc]init];
Group *group = [_arr objectAtIndex:indexPath.row]; //I have an array with 'Group' objects
//create vocabulary item
Vocabulary *vocabularyEntity = [NSEntityDescription insertNewObjectForEntityForName:#"Vocabulary" inManagedObjectContext:[delegate managedObjectContext]];
vocabularyEntity.prompt = #"Here is a cool prompt";
vocabularyEntity.definition = #"Here is an even cooler definition";
[delegate saveContext];
[group addTermsObject:vocabularyEntity];
I am getting this error, I used exception breakpoints and the error comes from the addTermsObject call.
[__NSDictionaryI addTermsObject:]: unrecognized selector sent to instance 0x74c4f70
The object I am trying to add is definitely a Vocabulary object, so i'm not exactly sure what the problem could be.
Any ideas?
Thank you!
The error message states that your
Group *group = [_arr objectAtIndex:indexPath.row];
is not a managed object as you expected, but an NSDictionary. Perhaps you fetched the array using
[fetchRequest setResultType:NSDictionaryResultType];
in the fetch request? In that case all the fetched objects are just dictionaries without
any connection to the managed object context, and you can't use these dictionaries to
establish any relationships.
UPDATE: Another error is here:
AppDelegate *delegate = [[AppDelegate alloc]init];
This allocates a new application delegate instead of using the existing one. This is
probably not what you want and you should replace it with
AppDelegate *delegate = [[UIApplication sharedApplication] delegate];

Setting Property with dot notation vs bracket notation

This sets the delegate correctly and everything functions as normal:
UINavigationController *nc = [segue destinationViewController];
RecipeAddViewController *rc = [nc.viewControllers objectAtIndex:0];
rc.delegate = self;
When I do:
[[[[[segue destinationViewController] viewControllers]objectAtIndex:0]delegate]self];
The delegate method is never called. Why is this?
The '.' Syntax would call getter and setter based on the usage. However in message syntax we need to call the explicit setter like bellow.
[[[[segue destinationViewController] viewControllers]objectAtIndex:0] setDelegate:self]

make two different fetch request per one method - looks like impossible

Dear community.
I was find a trouble for using a core data. Here is description:
From my AppDelegate i called my own class:
InitUpdateIXC *initAndUpdate = [[[InitUpdateIXC alloc] init] autorelease];
[initAndUpdate updateCarrierList:self.managedObjectContext];
Then i using there couple of methods, which update managedObjectContext, insert, add some entities e.t.c.
In this case i find limitation to using predicate twice per method:
First using working fine, and i seen results inside request:
NSFetchRequest *requestDestinationsForSale = [[NSFetchRequest alloc] init];
[requestDestinationsForSale setEntity:[NSEntityDescription entityForName:#"DestinationsListForSale"
inManagedObjectContext:managedObjectContext]];
[requestDestinationsForSale setPredicate:[NSPredicate predicateWithFormat:#"carrier.name like %#",carrierName]];
NSArray *destinationsForSale = [managedObjectContext executeFetchRequest:requestDestinationsForSale error:&error];
Inside the loop around MO:
for (NSManagedObject *destinationForSale in destinationsForSale)
{
for (NSManagedObject *code in [destinationForSale valueForKey:#"codesvsDestinationsList"])
{
i try to make new fetchRequest:
NSFetchRequest *requestDestinationWeBuy = [[[NSFetchRequest alloc] init] autorelease];
[requestDestinationWeBuy setEntity:[NSEntityDescription entityForName:#"DestinationsListWeBuy"
inManagedObjectContext:managedObjectContext]];
NSError *error = nil;
[requestDestinationWeBuy setPredicate:[NSPredicate predicateWithFormat:#"carrier.name like %#",carrierName]];
NSArray *destinationWeBuyList = [managedObjectContext executeFetchRequest:requestDestinationWeBuy error:&error];
ops... NSArray is empty...
if i do a same when i call method from AppDelegate:
[initAndUpdate updateRoutingTable:self.managedObjectContext];
It's a same class, same method, just called from main AppDelegate and little bit changed for using a just managed context, everything working fine.
Looks like managedObjectContext have final updates only when we leave class methods, which make updates.
Any comment will appreciated.
In your first fetch you are fetching on the entity DestinationsListForSale but in the second you are fetching on the entity DestinationsListWeBuy. The simplest explanation is that the same predicate does not produce the same result when applied to different entities.
Depending on the specifics of both the entities and the data being persistent at any one time, the same predicate will produce different outcomes when applied against different entities.
Indeed, that would be the expected behavior.

Resources