```// 1 override fun onCreateLoader(loaderId: Int,...
# codingconventions
e
Copy code
// 1
override fun onCreateLoader(loaderId: Int, args: Bundle?): Loader<Cursor> {
    val nickname = viewModel.nickname
    return CursorLoader(
        contactActivity,
        ContactsContract.Contacts.CONTENT_URI,
        PROJECTION,
        SELECTION,
        arrayOf(
            nickname, // just the nickname
            "$nickname %", // first name
            "% $nickname", // last name
            "% $nickname %" // middle name
        ),
        null
    )
}
or
Copy code
// 2
override fun onCreateLoader(loaderId: Int, args: Bundle?) =
    viewModel.nickname.let { nickname ->
        CursorLoader(
            contactActivity,
            ContactsContract.Contacts.CONTENT_URI,
            PROJECTION,
            SELECTION,
            arrayOf(
                nickname, // just the nickname
                "$nickname %", // first name
                "% $nickname", // last name
                "% $nickname %" // middle name
            ),
            null
        )
    }
1️⃣ 7
m
Or if the nickname is a specific type, could create an extension function instead of the
arrayOf
being hard-coded. Even if nickname isn't a specific type, if the 'show it with all the locations' is a common operation, it would be a useful extension function, and you could use the second w/o the
let
. 'show it with all locations' meaning the strings with 'nickname' and '%' in the various locations.
Otherwise, I'd vote for
1
, too. Using
let
with that many lines makes it harder to see start and end of the function. We're quite using to scanning the left for the curly-brace.
🥇 1
e
@Mike That’s a really good idea! I’ll do that.
g
0️⃣ do not use Loaders 😬