# Fetch core data string by int in a parameter function

**URL:** <https://forums.kodeco.com/t/fetch-core-data-string-by-int-in-a-parameter-function/176785>\
**Category:** Swift\
**Created:** [August 14, 2022, 6:15pm UTC](https://forums.kodeco.com/t/fetch-core-data-string-by-int-in-a-parameter-function/176785 "2022-08-14T18:15:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![timswift](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/timswift/32/110937_2.png) [@timswift](https://forums.kodeco.com/u/timswift)\
**Post date:** [August 14, 2022, 6:15pm UTC](https://forums.kodeco.com/t/fetch-core-data-string-by-int-in-a-parameter-function/176785/1 "2022-08-14T18:15:52Z")

</div>

In my swift code I attempted to fetch core data string using a int. I have 2 classes my base class and my helper class. In my base class that is where the func attempting to fetch the string. That func has a error message at fetchImageTxt.text = String(data: imageData) stating Missing argument for parameter ‘encoding’ in call. Don’t know how to resolve it.

BASE CLASS

```auto
     class ViewController: UIViewController, UINavigationControllerDelegate, UIImagePickerControllerDelegate {
      var fetchImageTxt = UITextField()

func getT(imageNo:Int) {
   // first check the array bounds
   let info = DataBaseHelper.shareInstance.fetchImage()
   if info.count > imageNo {
       // check if the data is available
       if let imageData = info[imageNo].img {
           fetchImageTxt.text = String(data: imageData)
           
           
       } else {
           // no data
           print("data is empty")
       }
   } else {
       // image number is greater than array bounds
       print("you are asking out of bounds")
   }
}
     }

```

HELPER CLASS

```auto
class DataBaseHelper {

static let shareInstance = DataBaseHelper()
let context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext
func fetchImage() -> [Info] {
    
  
    var fetchingImage = [Info]()
    let fetchRequest = NSFetchRequest<NSFetchRequestResult>(entityName: "Info")
    
    do {
        
        fetchingImage = try context.fetch(fetchRequest) as! [Info]
    } catch {
        print("Error while fetching the image")
    }
    
    return fetchingImage
}
}

```

![Screen Shot 2022-08-14 at 10.00.48 AM](https://files.chunter.kodeco.com/original/3X/2/9/2904bb4ac6f76006693eac104661304081c3ea81.png)

---

<div class="post-metadata">

**Author:** ![robertomachorro](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/robertomachorro/32/111603_2.png) [@robertomachorro](https://forums.kodeco.com/u/robertomachorro)\
**Post date:** [August 16, 2022, 9:11pm UTC](https://forums.kodeco.com/t/fetch-core-data-string-by-int-in-a-parameter-function/176785/2 "2022-08-16T21:11:42Z")

</div>

I have a lot of questions about what exactly you are trying to do. However, I can answer specifically about the _encoding_.

When you initialize a String with data, it is essentially a binary blob that will be converted into characters. The thing is that those characters can be encoded in many formats (most typically UTF-8, UTF-16, ASCII, etc). While the framework can do some educated guessing (for example UTF-8 sometimes contains a special sequence called BOM at the start of the data), it’s best if you supply such value.

---

<div class="post-metadata">

**Author:** ![system](https://s3.amazonaws.com/cdn.raywenderlich.com/community/forum-assets/noun-game-ghost-878668.png) [@system](https://forums.kodeco.com/u/system)\
**Post date:** [January 28, 2023, 10:16am UTC](https://forums.kodeco.com/t/fetch-core-data-string-by-int-in-a-parameter-function/176785/3 "2023-01-28T10:16:21Z")

</div>

Closed on January 28, 2023, 10:16am UTC

This topic was automatically closed after 166 days. New replies are no longer allowed.
