开发者

how to check condition in first class on the string of second class?

开发者 https://www.devze.com 2023-04-08 10:18 出处:网络
I want to check the conditon in my first class on the base of second class string.i mean i have a string mystr开发者_如何学编程 in second class which contain the value like \"sarab\".Now i want to use

I want to check the conditon in my first class on the base of second class string.i mean i have a string mystr开发者_如何学编程 in second class which contain the value like "sarab".Now i want to use condition in first class that if mystr="anything..".But i am not able to check the condtion.I dont know how to use second class string.Actually i have made one method in second class where i store the string value.Please tell me how i check the value of the string.My second class code is like that:

second.m

(void)mystrmethod
{
  mystr=[[NSMutableString alloc]init];
  mystr=@"sarab";
  NSLog(@" %@ ",mystr);
}

Now i want to check this str in my first class. Thank you


make this string variable global. then u can use this.


In your firstclass you need to import the second class like

#import "second.h"

and then you need to make an object of it like

Second *obj=[[Second alloc]init];

and then you can check the string value using

if{  [obj.mystr isEqualToString @"sarab"]}{
//then do something here
}

but all this work only if you define the string first and then compare it ..

hope this helps...


Declare your string in the appdelegate file and access it where ever you want using :

 appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
        if([appDelegate.<yourString> isEqualToString:@"<compareString>"]){
NSLog(@"appDelegate.<yourString> = %@",appDelegate.<yourString>);
           }
0

精彩评论

暂无评论...
验证码 换一张
取 消