# How to use it

Android library to simplify reading and writing to SharedPreferences, never write code like this anymore `prefs.edit().putString("someKey","someString").apply()`

Just create a model with wanted properties and default values like the this:

```kotlin
@Bulldog(name = "UserSettings")
object UserModel {
    const val id: Int = 20 // Default value
    const val email: String = "johndoe@gmail.com"
    const val likes: Long = 20L
    const val isPremium: Boolean = false
    const val minutesLeft: Float = 24.5F
}
```

{% hint style="info" %}
Init Bulldog context in your application class.

`bullDogCtx = applicationContext`
{% endhint %}

Bulldog will generate a class from this specification with the name **UserSettings.** Use it like a normal object to access values, under the hood it uses Kotlin delegated properties to read and writes values to SharedPreferences.

```kotlin
UserSettings().apply {
    id = 2
    email = "abc@gmail.com"
}
Log.d("PREFS", UserSettings().id)
Log.d("PREFS", UserSettings().toString())
```

{% hint style="info" %}
If no name is specified in `@Bulldog` annotation, the generated class will have the name of the specification object prefixed with Bulldog
{% endhint %}

### Read values

Just access object property like a normal object

```kotlin
Log.d("UserId", UserSettings().id)
```

### Write values

```kotlin
UserSettings().apply{
    id = 4
    Log.d("UserId", id)
}
```

### Clear values

Bulldog generates a clear method for each entry

```kotlin
UserSettings().apply{
    clearId()
    Log.d("UserId", id) // Will return the default value
}
```

### Print information

Bulldog also generates a `toString()` human readable implementation

```kotlin
Log.d("PREFS", UserSettings().toString())

// Ouput
// UserSettings  id=20, email=sergioserra@gmail.com, likes=20, isPremium=false minutesLeft=24.5
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://sserra.gitbook.io/bulldog/master.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
