Posts

Showing posts from 2019

A Simple SwiftUI animation

Image
struct ContentView: View {         @State private var animationAmount: CGFloat = 1             var body: some View {         Button("Tap Me") {         }         .padding(40)         .background(Color.red)         .foregroundColor(Color.white)         .clipShape(Circle())         .overlay(             Circle()                 .stroke(Color.red)                 .scaleEffect(animationAmount)                 .opacity(Double(2 - animationAmount))                 .animation(                     Animation.easeOut(duration: 1)                     .repeatForever(autoreverses: false)             )         )         .onAppear {                 self.animationAmount = 2         }     } } Credits: https://www.hackingwithswift.com/books/ios-swiftui/customizing-animations-in-swiftui

Dagger 03: Injecting via an AppModule using @Provides and @Inject

1. Create a class AppModule to inject stuff at the Application level. Add the AppModule in the modules section. Do not forget. @Module public class AppModule { } 2. In this class you can inject stuff like Retrofit instance or Glide Instance or a Constant class instance into your Activities by using @Provides . To Inject a String that represents a value, add the following code into the AppModule class    @Provides     static String someString() {         return "This is a test string";     } 3. To use these values inside your Activity using @Inject annotation in front the properties into which you wanna inject these values.      private static final String TAG = "AuthActivity";          @Inject     String injectedString;     @Override     protected void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.activity_auth);         Log.d(TAG, "onCreate: " + injectedString)

Dagger02: Inject Activities with @ContributesAndroidInjector

Components acts as Services . Activities/Fragments acts as Clients . Dagger Module: They are a place for dependencies to live so that we can add them to the components. 1. Create a ActivityBuildersModule class. This is the class where the DI of the Activity we want would happen. In this case it is AuthActivity . import dagger.Module; import dagger.android.ContributesAndroidInjector; @Module public abstract class ActivityBuildersModule {     @ContributesAndroidInjector     abstract AuthActivity contributeAuthActivity(); } 2. Add this module into the AppComponent class module section. @Component(         modules = {                 AndroidSupportInjectionModule.class,                 ActivityBuildersModule.class         } ) Now we can basically inject stuff into the AuthActivity . 3. Change the Activity to extend from DaggerCompatActivity .

Dagger01: Setting up

1. Install the Dagger Dependencies. def DAGGER_VERSION = "2.22" implementation "com.google.dagger:dagger:$DAGGER_VERSION" annotationProcessor "com.google.dagger:dagger-compiler:$DAGGER_VERSION" implementation "com.google.dagger:dagger-android:$DAGGER_VERSION" implementation "com.google.dagger:dagger-android-support:$DAGGER_VERSION" annotationProcessor "com.google.dagger:dagger-android-processor:$DAGGER_VERSION" 2. Create a BaseApplication class that extends DaggerApplication import dagger.android.AndroidInjector; import dagger.android.support.DaggerApplication; public class BaseApplication extends DaggerApplication {     @Override     protected AndroidInjector<? extends DaggerApplication> applicationInjector() {         return null;     } } 3. Add the BaseApplication class to the Manifest file.  <application         android:allowBackup="true"         android:name=".

Reading local files in an iOS Project

Reading String content from a Bundle

Concurrency in iOS - 1: Introduction to Grand Central Dispatch and Operations

In this blog series, I will try to simplify the concept of Concurrency in iOS using the Swift programming language. I myself have struggled with it for a long period of time and in the recent past started putting more effort into understanding it and implemented it certain apps successfully.  This whole series will evolve both as tutorial series with explanations of various important concepts with practical examples and a cookbook kind of recipes that you can pick up quickly in your iOS projects. Hope you find the series useful and without wasting any time lets get some concepts cleared out of the way. In iOS development ecosystem, there are majorly 2 ways to handle threads.  1. Grand Central Dispatch: For one time tasks we do not need to manage the state. 2. Operations: For reusable tasks that need to be performed multiple times. Grand Central Dispatch (referred as GCD) GCD is the implementation of C's libdispatch library which is used to queue up tasks and run them