Question: I'm trying to ask for runtime permission in ReactNative, but I'm always getting a "Permission is null" error in device screen.

here is the code:

```
import React, {Component} from 'react';
import {Text, View, StyleSheet, TextInput, Button} from 'react-native';
import {PermissionsAndroid} from 'react-native';

export default class HomeScreen extends React.Component {

  componentDidMount()
  {
    PermissionsAndroid.request(PermissionsAndroid.READ_PHONE_STATE) 
  }

  render () {
    return (
      <View style={styles.container}>
        <Text style={styles.paragraph}>Seja Bem vindo a BBTS!</Text>
        <Text style={styles.paragraph}>
          Matricula: {this.props.navigation.state.params.matricula}
        </Text>
        <Text style={styles.paragraph}>
          Email: {this.props.navigation.state.params.email}
        </Text>
        <Text style={styles.paragraph}>
            imei vem aqui
        </Text>
      </View>
    );
  }
}

```

I already put this on android manifest. My APi target is 26.

Any ideias?

Solution: 

```
async requestPermission() {
    try {
      const granted = await PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.READ_PHONE_STATE)

      if (granted === PermissionsAndroid.RESULTS.GRANTED) {
        console.log("You can read the phone state")
      } else {
        console.log("permission denied")
      }
    } catch (err) {
      console.warn(err)
    }
  }

  componentDidMount()
  {
    this.requestPermission();
  }

```

Answer: 
Aaah, I think get it... You want to know how the *key* is obtained to iterate over all elements on custom containers that do not have neither `__contains__()` nor `__iter__()` - simple, it works exactly using linear iteration until [`IndexError`](https://docs.python.org/3/library/exceptions.html#IndexError) is encountered, as stated in the documentation:

> 
> ... if a class defines `__getitem__()`, `x in y` is `True` if and only if there is a non-negative integer index `i` such that `x == y[i]`, and **all lower integer indices do not raise `IndexError` exception. (If any other exception is raised, it is as if in raised that exception)**.
> 
> 
> 

Case in point:

```
class CustomClass(object):

    def __getitem__(self, item):
        if item > 20:  # lets force the break so that it doesn't go to sys.maxsize
            raise IndexError()
        print(item)  # print the item requested
        # implied: return None so it doesn't match 5

result = 5 in CustomClass()  # this will keep printing numbers until 20

```
The purpose of these special methods is to give *you*, the designer of your data structure, a way to perform lookups in a fast way that is appropriate to your situation. For example, you could derive a class from `list` that is enhanced by a reverse index for fast lookup by value. (Obviously this would slow down insertion since the index needs to be updated, but let's assume that you'll be doing a lot of lookups so you know it's worth it.)

If your class has no way to improve on the default access, you don't need to define the special methods. Python will fall back on whatever is available, including sequential search.