---
title: "Unrecognized selector when setting NSArray property"  
description: "Unrecognized selector when setting NSArray property"  
author: "Anonymous User"  
published: 2015-07-28  
updated: 2015-07-29  
canonical: https://www.mindstick.com/forum/23383/unrecognized-selector-when-setting-nsarray-property  
category: "iphone"  
tags: ["iphone", "ios", "objective c"]  
reading_time: 1 minute  

---

# Unrecognized selector when setting NSArray property

I have a [method](https://www.mindstick.com/forum/166/webservice-method) that returns an [array](https://www.mindstick.com/articles/335/jagged-array-in-c-sharp-dot-net):

```
-(NSArray*)fetchStoresFromContext {     NSManagedObjectContext *context = [RKManagedObjectStore                                                        defaultStore].mainQueueManagedObjectContext;    NSFetchRequest *fetchRequest = [NSFetchRequest                                                        fetchRequestWithEntityName: @"Store"];    NSSortDescriptor *descriptor = [NSSortDescriptor sortDescriptorWithKey:                                                        @"name" ascending:YES];    fetchRequest.sortDescriptors = @[descriptor];    NSError *error = nil;    NSArray *fetchedObjects = [context executeFetchRequest:fetchRequest error:                                                         &error];    return fetchedObjects;}
```

If create a new NSArray and call this method like this:

```
NSArray *test = [self fetchStoresFromContext]; 
```

everything [works fine](https://answers.mindstick.com/qa/115732/my-software-works-fine-on-windows-10-but-crashes-on-windows-11-why). [test [count](https://www.mindstick.com/forum/157774/selecting-count-with-distinct)] returns 6.

I have the following [property](https://www.mindstick.com/blog/205/property-notification-in-c-sharp):

```
@property (nonatomic, strong) NSArray* stores; 
```

if I call _stores = [self fetchStoresFromContext] I get the following [error](https://yourviews.mindstick.com/view/88527/fixing-quickbooks-error-4120-reinstalling-vs-repairing):

-[__NSCFNumber [length](https://www.mindstick.com/interview/1915/what-is-the-difference-between-char_length-and-length)]: unrecognized [selector](https://www.mindstick.com/interview/23419/action-selector-in-mvc) sent to [instance](https://www.mindstick.com/forum/155658/testing-connection-to-cloud-sql-instance-with-a-mysql-client-from-vm-instance) 0x15e3c2f0

What's going on here? The property is an NSArray and the object is an NSArray as well so why am I having this [problem](https://yourviews.mindstick.com/view/81399/tackling-the-problem-of-unemployment-during-corona-pandemic)?

## Replies

### Reply by Tarun Kumar

The error means that your code is passing an NSNumber where the called code expects an NSString or some other object that has a length method.

Not clear enough...Is the error thrown when you do [_stores count] ?

If so, try to instantiate your array before counting :

```
_stores = [[NSArray alloc] initWithArray:[self fetchStoresFromContext]];
```


---

Original Source: https://www.mindstick.com/forum/23383/unrecognized-selector-when-setting-nsarray-property

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
