1

I am getting below response from the one of the third party SDK, Now how to check that my String value is exist in the response? And the key I need to compare with friendlyName key.

 channelList = (
     "<<TCHChannel: 0x2816df040>: sid: 'CH84', friendlyName: 'Mihir : MihirOza', attributes: '(null)'>",

     "<<TCHChannel: 0x2816dc480>: sid: '644d', friendlyName: 'Testchannel2', attributes: '(null)'>",

     "<<TCHChannel: 0x2816dff40>: sid: 'df38', friendlyName: 'privateios', attributes: '(null)'>" )  

Here is the code which I am using.

TCHChannels *channelsList = [[[ChatManager sharedManager] client] channelsList];
NSMutableOrderedSet<TCHChannel *> *newChannels = [[NSMutableOrderedSet alloc] init];
[newChannels addObjectsFromArray:[channelsList subscribedChannels]];
NSMutableArray<TCHChannel *> *temp = [[NSMutableArray alloc] initWithArray:[newChannels array]];
NSLog(@"channelList = %@",temp);

Thanks in advance.

Mihir Oza
  • 2,768
  • 3
  • 35
  • 61
  • Please check my answer, If it solves your issue then please mark it as approved so it will be helpful to others who have the same issues. – HardikS Jan 24 '20 at 06:20

2 Answers2

1

Try This :

NSPredicate *Pred = [NSPredicate predicateWithFormat:
                          @"TCHChannel.friendlyName == 'yourstring'"];
NSArray *arr = [temp filteredArrayUsingPredicate:pred];
Shahzaib Qureshi
  • 989
  • 8
  • 13
  • It's getting crash `reason: '[ valueForUndefinedKey:]: this class is not key value coding-compliant for the key TCHChannel.'` – Mihir Oza Jan 17 '20 at 12:05
1

Try below code

NSMutableArray<TCHChannel *> *temp = [[NSMutableArray alloc] initWithArray:[newChannels array]];
NSLog(@"channelList = %@",temp);

NSPredicate *Pred = [NSPredicate predicateWithFormat:
                          @"friendlyName == 'yourMatchString'"];
NSArray *arr = [temp filteredArrayUsingPredicate:pred];
HardikS
  • 656
  • 3
  • 10