---
title: "Converting data of NSData into bytes array in iOS"  
description: "Converting data of NSData into bytes array in iOS"  
author: "Anonymous User"  
published: 2015-11-20  
updated: 2015-11-20  
canonical: https://www.mindstick.com/forum/33616/converting-data-of-nsdata-into-bytes-array-in-ios  
category: "iphone"  
tags: ["iphone", "ios", "objective c"]  
reading_time: 1 minute  

---

# Converting data of NSData into bytes array in iOS

I have getting [problem](https://yourviews.mindstick.com/view/81399/tackling-the-problem-of-unemployment-during-corona-pandemic) with [conversion](https://www.mindstick.com/forum/1734/conversion-from-32-bit-integer-to-4-chars) of NSData into bytes array.\
this is the [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii) that I am using:

```
NSData *myData = [NSData dataWithContentsOfFile:pathOfFile];int dataLength = [myData length];Byte byteData[dataLength];byteData = [myData bytes];
```

My last line generating [error](https://yourviews.mindstick.com/view/88527/fixing-quickbooks-error-4120-reinstalling-vs-repairing) 'incompatible types in [assignment](https://www.mindstick.com/articles/126300/apa-citation-style-get-to-know-about-it-for-your-next-assignment)'.\
Can [anyone tell me](https://www.mindstick.com/interview/23033/can-anyone-tell-me-about-hadoop-toolbox) the correct way to do it.

## Replies

### Reply by Tarun Kumar

The error occurs because I think you are trying to set an allocated array when the return type is pointer.\
Use this to allocate data **getBytes:length:** call it like this:

```
[data getBytes:&byteData length:len];
```

Now, your allocated array is fills the data from the **NSData** object.


---

Original Source: https://www.mindstick.com/forum/33616/converting-data-of-nsdata-into-bytes-array-in-ios

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
