0

I have 2 objects in an NSMutableArray one is a CBPeripheral object and the other is an NSString.

Here you can see that the NSMutableArray contains the two objects: enter image description here

Then, in line 1249, I try to assign the 'periph' object to a CBPeripheral and in line 1252 I try to assign the 'ADVTname' to a text label.

Neither line 1249 nor 1252 is the correct syntax for what I am trying to do (line 1252 won't even compile).

Can someone tell me how to access my objects in my 'thisrow' NSMutableArray?

Thanks, Dale

EDIT #1: I am trying to understand how 'thisrow' has become an NSDictionay but I am stumped, here are all the code snippets that put the objects into 'thisrow'. Perhaps there is a flaw in the whole idea I have that is trying to remember the ADVTname for all peripherals that got added to _foundbleHalos.

//AFTER @interface foundblehalos was defined
@property (strong,nonatomic) NSMutableArray* foundbleHalos;

//in (void)centralManager > didDiscoverPeripheral
[_foundbleHalos addObject:@{@"periph": peripheral, @"ADVTname": ADVRTperipheralName}]; //2022-b70-3


//when I try to populate a TableView with all the ADVTnames we found:
NSMutableArray *thisrow = [_foundbleHalos objectAtIndex:indexPath.row];

blecell.textLabel.text = [NSString stringWithFormat:@"%@",thisrow.lastObject];

CBPeripheral* HaloForRow = (CBPeripheral*) thisrow[0];

EDIT #2: Well I think this following code is the answer to my topic question but I do not understand it since I do not know why 'thisrow' turned out to be a dictionary type when I originally defined it as an NSMutableArray:

//AFTER @interface foundblehalos was defined
@property (strong,nonatomic) NSMutableArray* foundbleHalos;

//in (void)centralManager > didDiscoverPeripheral
[_foundbleHalos addObject:@{@"periph": peripheral, @"ADVTname": ADVRTperipheralName}]; //2022-b70-3


//when I try to populate a TableView with all the ADVTnames we found:
NSDictionary *thisrow = [_foundbleHalos objectAtIndex:indexPath.row];

blecell.textLabel.text = thisrow[@"ADVTname"];

CBPeripheral* HaloForRow = (CBPeripheral*) thisrow[@"periph"];
6
  • 3
    thisrow is not an array. It is a dictionary Commented May 11, 2022 at 12:11
  • but I defined it as NSMutableArray in line1243, how did it get to be a dictionary? Commented May 11, 2022 at 12:20
  • You declared it as a NSMutableArray, but it's in fact a NSDictionary. it's like putting a Tag price marked with "Banana 1$" on an orange. It's still an orange... Commented May 11, 2022 at 13:10
  • You clearly wrote: [_foundbleHalos addObject:aDictionary], so it's a dictionary. Commented May 11, 2022 at 13:10
  • AHA, I did not realize that by using the syntax I did for adding objects to _foundbleHalos created a 'aDictionary', thanks I think I am happy now since my EDIT #2 code seems to give me the access to both the 'periph' and 'ADVTname' at the appropriate index of _foundbleHalos as the tableview populates. Commented May 11, 2022 at 13:18

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.