This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//This generic function mechanism similar to the `guard` statement in Swift but in Kotlin | |
inline fun <reified T> T?.guard(block: (T?) -> Nothing): T { | |
return this ?: block(this) | |
} | |
//This generic function mechanism simillar to the `apply` difference is that returning Unit. | |
@OptIn(ExperimentalContracts::class) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Activity extends AppCompatActivity { | |
@Override | |
protected void onCreate(@Nullable Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
SingletonSharePrefrences.getInstance().putString("KEY_NAME" , "MACK"); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Now you can use it this way | |
CoroutineScope(Dispatchers.IO).launch { | |
val user = User(); | |
UserInfoAPI().add(user) | |
UserInfoAPI().edit(user) | |
UserInfoAPI().delete(10) | |
} |