Wednesday, July 25, 2018

How to copy Xcode from one Mac to another Mac

Move Xcode from one Mac to another Mac 

Steps 

1- Copy Xcode.app file and paste to new mac's `Application` folder
2- Copy `~/Library/Developer/` to new mac's location ~/Library/Developer/ folder
3-

Issue -
Xcode won't start, stuck on 'Verifying “Xcode”…'

Solution 
xattr -d com.apple.quarantine '/Applications/Xcode.app'

By running above command , you are giving persission to Xcode ti install it without verifying it. 

 4- open Xcode in Application directory. 

Cheers !!!!

Android Architecture Component ROOM

Why ROOM Library ?

In android app, We convert raw data into structural data . we use SQLite core library to achieve it .

 It handles CRUD (Create, Read, Update and Delete) operations required for a database. Java classes and interfaces for SQLite are provided by the android.database. SQLite maintains an effective database management system. But this conventional method has its own disadvantages.


  • You have to write long repetitive code, which will be time-consuming as well as prone to mistakes.
  • Syntax errors in queries
  • No compile time error detection (Time consuming)
  • Parsing is required to convert data to Plain Old Java Objects (POJO) objects
  • It is very difficult to manage SQL queries for a complex relational database.
To overcome this, Google has introduced Room Persistence Library.


What is ROOM? 

Room provides the abstraction layer over the SQLite DB. ROOM is not a database
It has extended features and ease of use over android SQLite library .

Componentes

There are three main components of Room-
  • Database: Contains the database holder and serves as the main access point for the underlying connection to your app's persisted, relational data.
    The class that's annotated with @Database should satisfy the following conditions:
    • Be an abstract class that extends RoomDatabase.
    • Include the list of entities associated with the database within the annotation.
    • Contain an abstract method that has 0 arguments and returns the class that is annotated with @Dao.
    At runtime, you can acquire an instance of Database by calling Room.databaseBuilder() orRoom.inMemoryDatabaseBuilder().
  • Entity: Represents a table within the database.   
  1. tableName attribute is used to define the name of the table
  2. Every entity class must have at-least one Primary Key field, annotated with @PrimaryKey
  3. Fields in entity class can be annotated with @ColumnInfo(name = “name_of_column”) annotation to give specific column names
         
  • DAO: Contains the methods used for accessing the database.

  1. Data Access Object is either be an interface or an abstract class annotated with @Doa annotation, containing all the methods to define the operations to be performed on data. The methods can be annotated with
    • @Query to retrieve data from database
    • @Insert to insert data into database
    • @Delete to delete data from database
    • @Update to update data in database



                                 The app uses the Room database to get the data access
  objects, or DAOs, associated with that database. The app then uses each DAO to
  get entities from the database and save any changes to those entities back to
  the database. Finally, the app uses an entity to get and set values that
  correspond to table columns within the database.




How to Implement?

Before jump into details, Room uses annotations heavily to decrease the boilerplate code.






Why and What is ViewModel : Android Architecture Component

Why We need model ?


A ViewModel holds your app's UI data in a lifecycle-conscious way that survives configuration changes. Separating your app's UI data from your Activity and Fragment classes lets you better follow the single responsibility principle: Your activities and fragments are responsible for drawing data to the screen, while your ViewModel can take care of holding and processing all the data needed for the UI.

In the ViewModel, use LiveData for changeable data that the UI will use or display. Using LiveData has several benefits:

You can put an observer on the data (instead of polling for changes) and only update the
the UI when the data actually changes.

The Repository and the UI are completely separated by the ViewModel. There are no database calls from the ViewModel, making the code more testable.


What is ViewModel ?

The ViewModel's role is to provide data to the UI and survive configuration changes. A ViewModel acts as a communication center between the Repository and the UI. You can also use a ViewModel to share data between fragments. The ViewModel is part of the lifecycle library.






Warning: Never pass context into ViewModel instances. Do not store Activity, Fragment, or View instances or their Context in the ViewModel.


For example, an Activity can be destroyed and created many times during the lifecycle of a ViewModel as the device is rotated. If you store a reference to the Activity in the ViewModel, you end up with references that point to the destroyed Activity. This is a memory leak.


If you need the application context, use AndroidViewModel


Important: ViewModel is not a replacement for the onSaveInstanceState() method, because the ViewModel does not survive a process shutdown.