No visible #interface for 'JSQSystemSoundPlayer' declares the selector 'playSoundWithFilename:fileExtension:' - ios

This is where my build fails in JSQSystemSoundPlayer. I cannot get around this.
if (asAlert) {
[[JSQSystemSoundPlayer sharedPlayer] playAlertSoundWithFilename:fileName fileExtension:kJSQSystemSoundTypeAIFF];
}
else {
[[JSQSystemSoundPlayer sharedPlayer] playSoundWithFilename:fileName fileExtension:kJSQSystemSoundTypeAIFF];
}

According to the header file, I think you need to include a completion block (which you can set to nil if you don't want anything doing).
if (asAlert) {
[[JSQSystemSoundPlayer sharedPlayer] playAlertSoundWithFilename:fileName fileExtension:kJSQSystemSoundTypeAIFF completion:nil];
} else {
[[JSQSystemSoundPlayer sharedPlayer] playSoundWithFilename:fileName fileExtension:kJSQSystemSoundTypeAIFF completion:nil];
}

Related

Comparing class is giving incorrect output

I am using below code to check view controllers.
NSLog(#"addProductClicked 1===%#", self.class);
NSLog(#"addProductClicked 2===%#", [CategoriesViewController class]);
if ([self.class isKindOfClass:[CategoriesViewController class]]) {
NSLog(#"you go it right");
} else {
NSLog(#"you go it wrong");
}
The output I get is as below.
addProductClicked 1===CategoriesViewController
addProductClicked 2===CategoriesViewController
you go it wrong
Any idea what is going wrong?
Just to update, below is what I have defined my view controller...
#interface CategoriesViewController : GlobalViewController {
Now in GlobalViewController I have method where I am checking above...
The variable you want to class check should be passed in as an object, not as a class.
if ([self isKindOfClass:[CategoriesViewController class]]) {
NSLog(#"you go it right");
} else {
NSLog(#"you go it wrong");
}
Thats is wrong comparison. You call isKindOfClass: on the object of that class. Something like this:
CategoriesViewController *obj = [[CategoriesViewController alloc] init];
[obj isKindOfClass:CategoriesViewController];
In your case you probably want to put a check on self.

iOS block function called twice

I have a block function defined as the below:
#property (atomic, assign) bool callInProgress;
//in implementation:
- (void)synchronize:(void(^)(void(^unlock)()))block {
if (!_callInProgress) {
_callInProgress = YES;
[_tableView setScrollEnabled:false];
block(^{
[_tableView setScrollEnabled:true];
_callInProgress = NO;
});
}
}
Then when I do:
[self synchronize:^(void(^unlock)()) {
}];
and I set a break point at that [self synchronize..], the break point gets hit twice no matter what! If I add a body:
/*break point on this line*/ [self synchronize:^(void(^unlock)()) {
NSLog(#"HERE");
unlock();
}];
HERE gets printed ONCE but the break point gets hit twice!
Any ideas why?
The breakpoint is being hit once when you reach the synchronize call, and once when you enter the callback block. Both are on the same line.

NS_CLASS_AVAILABLE not working

I'm trying to use NS_CLASS_AVAILABLE (NS_CLASS_AVAILABLE_IOS to be precise) in a project but it seems it doesn't work.
I have tried:
NS_CLASS_AVAILABLE_IOS(7_0) #interface Dummy : NSObject
#end
Then when I have tried to check if the class is available:
if ([Dummy class]) {
NSLog(#"Dummy available");
} else {
NSLog(#"Dummy not available");
}
I always get "Dummy available", even in the iOS 6 simulator.
To check I have tried with NSURLSession:
if ([NSURLSession class]) {
NSLog(#"NSURLSession available");
} else {
NSLog(#"NSURLSession not available");
}
And, this time, I correctly get "NSURLSession not available".
Is there something I'm doing wrong?
Is there a compiler flag or something?

Calling of methods in ios

I am very new to ios and having a problem to call four different methods one after the other, as I would like to call them after comparison like if(number<6)
method2->method3->method4->method1-> such that it would make a loop until the comparison of (number)become false.
Also I want method1 to be activated in viewDidLoad.
Something like this, if I understood your question properly
[[[method2 method3] method4] method1]
You can use
[yourObject performSelector:#selector(method1:)]
You can call it on any NSObject (and subclasses of course). You may want to try before :
[yourObject respondToSelector:#selector(method1:)]
This will tell you if your object has this method or not (avoid exceptions and errors).
More informations on the official documentation of performSelector.
use [self method1]; somewhere else and use as follows:
-(void) method1
{
[self method2];
}
-(void) method2
{
[self method3];
}
-(void) method3
{
[self method4];
}
-(void) method4
{
// do if you need.
}
Or Try NSNotificationCenter
I hope i'm interpreting your question correctly. But here's a simple implementation...
- (void)viewDidLoad {
[super viewDidLoad];
[self method1];
}
- (void)method1 {
/* do stuff */
[self method2];
}
- (void)method2 {
/* do stuff */
[self method3];
}
- (void)method3 {
/* do stuff */
[self method4];
}
- (void)method4 {
/* do stuff */
}
-(void) method1
{
if (number<6)
{
[self method2];
}
}
-(void) method2
{
[self method3];
}
-(void) method3
{
[self method4];
}
-(void) method4
{
[self method1];
}

What's wrong with this switch statement?

Image Link
As you can see from the output, the switch statement completely skips over case 'view1'. And I'm having trouble understanding what the warnings mean.
Try to change the method signature to
- (void)switchViewTo:(NSString *)view
{
if ([view isEqualToString:#"view1"]) {
NSLog(#"view 1");
} else if ([view isEqualToString:#"view2"]) {
NSLog(#"view 2");
} else {
NSLog(#"whatever");
}
}
In the designated initializer you call [self switchToView:#"view1"];

Resources