Source Code Management Using Bitbucket

Source Code Management Using Bitbucket

What is Source Code Management & version control :

  • While working on important projects like websites, software, desktop or mobile application it becomes necessary to handle the source code at a safe place. Specifically in websites & applications requires regular updates & each time the source will be updated too. So it’s important to keep the back up of the source code.
  • Also, there are some cases where multiple persons working as a team on the same project so at that time they will work on the similar source code. So at that time its good to maintain the backup regularly so if any issue arrives at any stage we can roll back the changes or can recover from the issue by using back source.
  • Developers often keep the backup on their local systems or the generic servers where whole organization source code is maintained. Now consider a case when if any hardware issue arrives & you couldn’t be able to recover the source from the local system it can become severe issue & cost you a lot. So there would be a common solution where we should be able to manage the latest source code as well as we can manage version control.

 

What is Bitbucket & how it helps :

  • Bitbucket is basically a hosting service which allows you to sign in for free & allows to create repositories where you can take backup of your source code & perform some advanced operations as well
  • Storing a source code on bitbucket is not only free but it’s also a safe option. Consider if you are working on 40-50 projects where it becomes tidy for you to keep back of all of the projects on your local system. Now if you use Bitbucket, in that case, you can manage all of your source codes & keep your system free
  • What you can do is once you complete the update of your app or website then upload final source on bitbucket
  • Now later on when new version update arrives you can get the latest source from the bitbucket do modifications whatever requires & once you finish you can resubmit the changes back to the bitbucket server

 

Key benefits of using Bitbucket :

  • If you are an individual developer, It provides a free sign in & can upload unlimited repositories. For the organization, it provides management repositories up to 5 persons into a single team
  • Easy & quick to set up & uploads. Also can create unlimited repositories
  • It’s a safe option as it also allows you to keep your repositories private where. If you keep it private no other persons will find your repositories
  • Allows advance operations like push changes, version control

Read more: Set up UILocalNotification in iOS Swift/Objective C

If you are new to bitbucket source code management & haven’t tried it yet that you must read this carefully.

Here is step by step explanation of source code management using Bitbucket,

  • If you are new to bitbucket & haven’t signed in yet than Signup first.

https://bitbucket.org/account/signin/

  • Ok, so we have bitbucket account now next step is to make sure our system is ready for it or not. So go to Application folder & see if you have Github desktop application installed or not. If no than download it from here & install: https://desktop.github.com
  • Now if you are first time uploading git repository of your source code then create a new repository on bitbucket. For that go to Bitbucket site & click on a + button on left panel & select repository & fill up the details.
  • Now repository is created & ready to receive the source code. So the next step is keeping the copy of your source code to a desktop. Note: reason, why I prefer to keep it on a desktop, is in any other path there might be a chance to have white spaces on the file path & that may not allow working some of the commands on terminal. So always prefer to keep the copy of your source code on the desktop & also make sure it’s not compressed file. Keep it unzipped.
  • Open terminal & navigate to the desktop path

$ cd desktop

  • Now go inside your project folder

$ cd project-name

  • Initialise git command like this :

$ git init

  • Add ‘.’ (dot) Reference for the first commit on your repository

$ git add.

  • Now perform initial commit by adding some text to the readme file like this (You can change text written between single quotes) :

$ git commit -m  ‘Initial commit with contributors’

  • Now its time to add repository path origin URL

$ git remote add origin your_repository_UR

Like this: $ git remote add origin https://[email protected]/MyComp/myapp.git

  • Finally, the last option is to push your source to the bitbucket server.

$ git push origin master -f

Once above steps followed it will first ask for the password of your bitbucket account for the first time only. Later on, it will be saved to your keychain account & will be accessed directly from there.

Share
Basic iOS Application Animation Tutorial

Basic iOS Application Animation Tutorial

Using animations in iOS Application can make it more impressive. A user always loves to use something new innovative things. There are few basic animations available in both Objective C & Swift by using that we can covert a normal user experience to something special.

It’s not necessary that it will make a vast difference in the application. Some of the users even do not notice such things. But at least that will make your application stand differently than the other similar application with just a few lines of codes.

Here are some basic animation techniques available which you can utilize into your application to make it different.

View Transition animations :

This will allow page curl animation while presenting new view controller.

For Presenting :

NextView *ivc = [mainstoryboard instantiateViewControllerWithIdentifier:@”nextview”];

[UIView transitionWithView:APP_DEL.window duration:0.5 options:UIViewAnimationOptionTransitionCurlUp animations:^{

}completion:nil];

[self presentViewController:ivc animated:NO completion:nil];

 

For Dismissing :

[UIView transitionWithView:APP_DEL.window duration:0.5 options:UIViewAnimationOptionTransitionCurlDown animations:^{

}completion:nil];

[self dismissViewControllerAnimated:NO completion:nil];

 

Here are the more transition animations available which you can use in place of curl animations :

UIViewAnimationOptionTransitionFlipFromLeft    = 1 << 20,

UIViewAnimationOptionTransitionFlipFromRight   = 2 << 20,

UIViewAnimationOptionTransitionCurlUp          = 3 << 20,

UIViewAnimationOptionTransitionCurlDown        = 4 << 20,

UIViewAnimationOptionTransitionCrossDissolve   = 5 << 20,

UIViewAnimationOptionTransitionFlipFromTop     = 6 << 20,

UIViewAnimationOptionTransitionFlipFromBottom  = 7 << 20,

 

View animations with completion :

This is simple view frame animation which allows you to move view through out the animation. It will used to open view with moving animation.

view.frame = CGRectMake(0, 0, 0, 0);

[UIView animateWithDuration:0.7 animations:^{

view.frame = CGRectMake(0, 0, 375, 667);

} completion:^(BOOL finished) {

// On completion show objects on view

}];

 

This is simple view frame animation which allows you to show view with blink effect.

view.alpha = 0.0;

[UIView animateWithDuration:0.7 animations:^{

view.alpha = 1.0;

} completion:^(BOOL finished) {

// On completion show objects on view

}];

More animation methods can be used with few more features :

  • (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^ __nullable)(BOOL finished))completion NS_AVAILABLE_IOS(4_0);
  • (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations NS_AVAILABLE_IOS(4_0); // delay = 0.0, options = 0,
  • (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay usingSpringWithDamping:(CGFloat)dampingRatio initialSpringVelocity:(CGFloat)velocity options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^ __nullable)(BOOL finished))completion NS_AVAILABLE_IOS(7_0);
Share
SQLite Useful Functions for Beginners

SQLite Useful Functions for Beginners

SQLite database provides advanced functions for adding, removing, updating records into a database. It also allows performing some of the advanced levels of operations like database migration, Inner join, a grouping of tables etc.

Its normally used to store large records into the application such as managing user list, or offline records of web-based data to make sure it supports an offline load of the data in case of no internet connection.

Running with SQL functions is as faster as any other database storage options & its more convenient options too. The reason is it provides advance inserting & deleting features & clauses which allows developers to perform complex operations over a local database.

So here are some basic functions which we normally use in iOS Application for managing local database.

Save record :

– (void) doSaveMyData  {

sqlite3 *database;

[self CheckConnection];

if (sqlite3_open([dbpath UTF8String], &database) == SQLITE_OK)  {

NSString *query = [NSString stringWithFormat:@”insert into myTable values(‘%@’, ‘%@’)”, value1, value2];

const char *sqlStmt = [query UTF8String];

sqlite3_stmt *cmpSqlStmt;

sqlite3_prepare_v2(database, sqlStmt, -1, &cmpSqlStmt, NULL);

sqlite3_step(cmpSqlStmt);

sqlite3_finalize(cmpSqlStmt);

}

sqlite3_close(database);

}

For Check Database Connection (This will commonly used before any database operation)

-(void)CheckConnection {

NSArray *docpath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

NSString *docdir = [docpath objectAtIndex:0];

dbpath = [docdir stringByAppendingPathComponent:database];

BOOL success;

NSFileManager *fm = [NSFileManager defaultManager];

success = [fm fileExistsAtPath:dbpath];

if(success) {

return;   }

NSString *dbPathFromApp = [[[NSBundle mainBundle]resourcePath]stringByAppendingPathComponent:database];

[fm copyItemAtPath:dbPathFromApp toPath:dbpath error:nil];

}

Get list of records :

-(void)doGetRecords:(NSString*)strCatID {

[self CheckConnection];

if (arrList.count > 0) {

[arrList removeAllObjects];

arrList = nil;

}

arrOutFitsList = [[NSMutableArray alloc] init];

sqlite3 *database;

if (sqlite3_open([dbpath UTF8String], &database)==SQLITE_OK) {

NSString *query = [NSString stringWithFormat:@”select * from myTable where cat_id = ‘%@””,strCatID];

const char *sqlStmt = [query UTF8String];

sqlite3_stmt *cmpsqlstmt;

if (sqlite3_prepare_v2(database, sqlStmt, -1, &cmpsqlstmt, NULL) == SQLITE_OK) {

while (sqlite3_step(cmpsqlstmt) == SQLITE_ROW) {

DetailDict *obj = [DetailDict new];

obj.id = [NSString stringWithFormat:@”%d”,(int)sqlite3_column_int(cmpsqlstmt, 0)];

obj.Tag = [NSString stringWithUTF8String:(char*)sqlite3_column_text(cmpsqlstmt, 1)];

[arrOutFitsList addObject:obj];

}

sqlite3_finalize(cmpsqlstmt);

}

sqlite3_close(database);

}

Update record :

-(void)doUpdaterecord {

[self CheckConnection];

sqlite3 *database;

if (sqlite3_open([dbpath UTF8String], &database)==SQLITE_OK) {

NSString *query = [NSString stringWithFormat:@”update myTable set cat_id=’%@’, Tag=’%@'”, self.objDetailsDict.cat_id, self.objDetailsDict.Tag];

const char *sqlStmt = [query UTF8String];

sqlite3_stmt *cmpSqlStmt;

sqlite3_prepare_v2(database, sqlStmt, -1, &cmpSqlStmt, NULL);

sqlite3_step(cmpSqlStmt);

sqlite3_finalize(cmpSqlStmt);

}

sqlite3_close(database);

}

Remove Record :

-(void)doRemoveRecord:(NSString*)stID {

[self CheckConnection];

sqlite3 *database;

if (sqlite3_open([dbpath UTF8String], &database)==SQLITE_OK) {

NSString *query = [NSString stringWithFormat:@”DELETE FROM myTable WHERE id=’%@'”,stID];

const char *sqlStmt = [query UTF8String];

sqlite3_stmt *cmpSqlStmt;

sqlite3_prepare_v2(database, sqlStmt, -1, &cmpSqlStmt, NULL);

sqlite3_step(cmpSqlStmt);

sqlite3_finalize(cmpSqlStmt);

}

sqlite3_close(database);

}

Count Number of Records :

-(int)doCountToalRecords:(NSString *)ID {

[self CheckConnection];

int totalIS = 0;

sqlite3 *database;

if (sqlite3_open([dbpath UTF8String], &database)==SQLITE_OK) {

NSString *query = [NSString stringWithFormat:@”SELECT Count(*) FROM myTable where cat_id = ‘%@'”,ID];

const char *sqlStmt = [query UTF8String];

sqlite3_stmt *cmpsqlstmt;

if (sqlite3_prepare_v2(database, sqlStmt, -1, &cmpsqlstmt, NULL) == SQLITE_OK) {

while (sqlite3_step(cmpsqlstmt) == SQLITE_ROW) {

totalIS = sqlite3_column_int(cmpsqlstmt, 0);

}

}

sqlite3_finalize(cmpsqlstmt);

sqlite3_close(database);

}

return totalIS;

}

Add new field to existing table :

-(void)doAddNewFieldToTable {

sqlite3 *database;

if (sqlite3_open([dbpath UTF8String], &database)==SQLITE_OK) {

NSString *query = @”ALTER TABLE myTable ADD COLUMN newField Varchar”;

const char *sqlStmt = [query UTF8String];

sqlite3_stmt *cmpsqlstmt;

if (sqlite3_prepare_v2(database, sqlStmt, -1, &cmpsqlstmt, NULL) == SQLITE_OK) {

while (sqlite3_step(cmpsqlstmt) == SQLITE_DONE) {

NSLog(@”Success”);

}

}

sqlite3_finalize(cmpsqlstmt);

sqlite3_close(database);

}

}

So in this blog we have covered up all basic operations performed in sqlite database such as inserting, fetching, updating, removing records & also for counting number of records, adding new field to existing table while working with Objective C in iOS Application.

Share
Convert Your Project to Latest Swift Version

Convert Your Project to Latest Swift Version

Whenever new Xcode version release or any new OS releases apps developed with the swift language are needed to convert to the new swift version. There might be syntax changes or any bugs solving or something done in the swift language which requires apps to be updated with latest stable version.

Now, in this case, developers often try to make compatibility by manually running app & finding the bugs. Now, this process consumes more time & sometimes it takes too long to debug & find the exact solution. Overall it becomes tidy process & not exactly what Apple prefers.

So here are the proper steps to perform the process:

First of all, open your project into latest Xcode version & make sure don’t run it the first time.

Go to Edit -> Convert -> To current swift syntax

This will open hierarchy of files. Make sure there will be all files selected with a check mark which you wants to convert to latest swift syntax. If any files not selected or you don’t want that to a concert than manually uncheck it. Then clicking on done will do the rest of the work.

Note :

In new swift version, latest swift conversion process works perfectly & don’t require actually to manually resolve any errors. But still, there could be the chance of any errors skipped by the compiler or unable to detect the difference will keep remain & can show an error so that requires handling manually.

Share
How to save data to PList files in iOS

How to save data to PList files in iOS

While working with iOS Applications there are various ways to store data locally into an app. Such as NSUserdefaults, SQLite database, Plist file, NSKeyArchiever, Core data etc.

A developer can choose any of the medium suitable for the application. It can be measured by the complexity of the data & length of the data. Usually, plist is used for storing flag values or for in-app purchase settings or for storing some of the key settings of the application. This kind of data doesn’t require any complex data structure of any advanced functions.

Plist file doesn’t require to fire any queries nor any complex process for fetching or updating data. So it loads faster than the other data storage options.

That is the reason why its more often used in the game for storing scores, statistics of the game. Implementation is also very easy as just a few lines of code required to set up 2 main functions for handle plist files records. First for reading records, Second for writing records.

Here are few easy steps with a graphical representation for creating, reading & writing plist file.

Create New plist file :

Right click on projects & click create new file

From Resources select property list & name it as you want (For ex: mySettings.plist).

Set up prefix value into plist :

You can store anything type of variable like Dictionary, Array, Strings to the plist. Note that the root type will remain NSDictionary always. Lets say we have to store string value inside plist file.

So here i am storing string value by setting up prefix value to 0. We can store & manage multiple strings, arrays & dictionary values inside same plist file.

Writing value to plist file:

-(void)doWriteSettingFilePlist {
NSError *error;
NSString *path = [documentsDirectory stringByAppendingPathComponent:@”SettingFile.plist”];
NSFileManager *fileManager = [NSFileManager defaultManager];
// if File not exist at the same path
if (![fileManager fileExistsAtPath: path]) {
NSString *bundle = [[NSBundle mainBundle] pathForResource:@”SettingFile” ofType:@”plist”];
[fileManager copyItemAtPath:bundle toPath: path error:&error];
}
NSMutableDictionary *data = [[NSMutableDictionary alloc] initWithContentsOfFile:path];
[data setObject:self.strProVersion forKey:@”proversion”];
[data writeToFile:path atomically:YES];
}

Reading from plist file :

-(void)doReadSettingFilePlist {
NSError *error;
NSString *path = [documentsDirectory stringByAppendingPathComponent:@”SettingFile.plist”];
NSFileManager *fileManager = [NSFileManager defaultManager];
// if File not exist at the same path
if (![fileManager fileExistsAtPath: path]) {
NSString *bundle = [[NSBundle mainBundle] pathForResource:@”SettingFile” ofType:@”plist”];
[fileManager copyItemAtPath:bundle toPath: path error:&error];
}
NSMutableDictionary *data = [[NSMutableDictionary alloc] initWithContentsOfFile:path];
self.strProVersion = [data valueForKey:@”proversion”];
}

Notes :

Plist is more faster in terms of fetching data & handle small amount of records. Although its no recommended for use in high level database records storage where more complex operations are requires to handle. One more drawback is plist doesn’t provide update functions like SQLite does. Its just simply overwrites the data.

Overall its still useful feature for handling default app settings of the app like flag values sound, inApp purchase properties etc. with less coding & less efforts & minimum compilation time.

Share
Set up UILocalNotification in iOS Swift/Objective C

Set up UILocalNotification in iOS Swift/Objective C

 

UILocalNotification helps to schedule specific notification for the user on specific date & time. As the name suggests that its handled & called from inside the application locally. So it can work without internet connection.

Its used in an application for various purpose like :

  • Keeping user active into application & make sure app usage increases
  • Notify for some reminders in the application
  • Used as a reminder feature inside the application
  • Keep highlighting for the features inside the application
  • Daily usage reminder for the application

So here is the tutorial about how we can create a UILocalNotification & manage it.

Objective C :

 

Create new notification :

-(void)doCreateLocalNotification {

NSDate *now = [NSDate date];

NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];

NSDateComponents *components = [calendar components:NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay fromDate:now];

[components setHour:18];

[components setMinute:1];

[components setSecond:10];

NSDate *firedate = [calendar dateFromComponents:components];

UILocalNotification *notification = [[UILocalNotification alloc] init];

notification.fireDate = firedate;

notification.alertBody = @”Hey how are you ? Have you used application today ?”;

notification.repeatInterval = NSCalendarUnitDay;

[[UIApplication sharedApplication] scheduleLocalNotification:notification];

}

Destry all local notifications :

-(void)doDestryNotification {

[[UIApplication sharedApplication] setApplicationIconBadgeNumber: 0];

[[UIApplication sharedApplication] cancelAllLocalNotifications];

}

Read more: Healthy iOS Development Tips & Tricks

Swift :

 

Create new notification :

func doCreateReminder() {

let dateToFire = NSDate().addingTimeInterval(60*60*24*7)

let notification = UILocalNotification()

notification.fireDate = dateToFire as Date

notification.alertBody = NSLocalizedString(“localalert”, comment: “”)

let dict:NSDictionary = [“type” : “reminder”]

notification.userInfo = dict as! [String : String]

notification.repeatInterval = NSCalendar.Unit(rawValue: UInt(0))

notification.soundName = UILocalNotificationDefaultSoundName

UIApplication.shared.scheduleLocalNotification(notification)

}

Destry all local notifications :

func doDestryAllNotification() {

UIApplication.shared.applicationIconBadgeNumber = 0

UIApplication.shared.cancelAllLocalNotifications()

}

 


Tags: iOS, iOS app, iOS Application Development Services, iPhone Application Development Company, Mobile Apps Development, Update
Share
Share