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

```
> 
> How does it perform a search over all such `i`?
> 
> 
> 

This depends, pretty much on the data structure of the object in which the search is performing on. For example if you have a `list` object, the complexity of membership checking is O(n) and if you have a data structure that uses hashtable accessing its items (the `__getitem__` attribute) such as dictionary or set the complexity is approximately O(1).

So in general for user defined objects it works as it's explained in documentation. For objects without hash table it's a linear search and for objects with hash table its a constant search.