Hello:
I have the following scenario:
Using NSFetchRequest i get a count of items returned as:
numberRecords = items.count
I want to get a random record based on the number of records in "numberRecords".
Now i can get a random value using : selector = Int.random(in: 0 ..< 355)
But how can I use "numberRecords" to get a numerical value?
Thanks.
From what I understand, there is no easy and robust way to fect a random element directly.
See detailed discussion here
Unless to select a search key randomly and then fetch.
If the key includes a sequential number, that shouyd be easy
https://stackoverflow.com/questions/34917149/how-to-randomly-choose-an-element-from-coredata-swift
But, why not fetch all results and then do the random pick ?
Note: looks like you expect fetch to paly as an agent that executes in CoreData to fetch a random item.
AFAIK, fetch has not such a capability, it does "only" pattern matching.