Question: I am trying to log into instagram without the use of the API but recieve a 403 response? Credentials are correct but still getting the response. Any help on this matter?

```
import requests

main_url = 'https://www.instagram.com/'
login_url = main_url+'accounts/login/'
user_agent = 'User-Agent: Mozilla/5.0 (iPad; CPU OS 6_0_1 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A523 Safari/8536.25'

session = requests.session()
session.headers = {"user-agent": user_agent}
session.headers.update({'Referer': main_url})

req = session.get(main_url)
session.headers.update({'set-cookie': req.cookies['csrftoken']})
print(req.cookies['csrftoken'])
print(req.status_code)

login_data = {"username": "<user>", "password": "<pass>"}

login = session.post(login_url, data=login_data, allow_redirects=True)
print(login.cookies['csrftoken'])
print(login.status_code)
session.headers.update({'set-cookie': login.cookies['csrftoken']})

cookies = login.cookies

print(login.headers)
print(login.status_code)

```

Answer: 
You need to specify an appropriate sort descriptor.

I recommend to make the function `throw` and hand over the error.

```
class func fetchObject() throws -> [Dice] {
    let context = getContext()
    let fetchRequest : NSFetchRequest<Dice> = Dice.fetchRequest()
    fetchRequest.sortDescriptors = [NSSortDescriptor(key: "timestamp", ascending: false)]
    return try context.fetch(fetchRequest)
}

```

Note: The `fetch` operation returns `[Dice]`. A type cast is not needed.
You can do like this

```
class func fetchObject() -> [Dice]? {
            var dices:[Dice]? = nil
            let context = getContext()
            let fetchDice: NSFetchRequest<Dice> = Dice.fetchRequest()
            let sortDescriptor = [NSSortDescriptor.init(key: "timestamp", ascending: false)]
            fetchDice.sortDescriptors = sortDescriptor
            do
            {
                dices = try context.fetch(fetchDice) 
                return dices
            }catch(let error) {
                print(error.localizedDescription)
                return dices
            }
   }

```