How to Create Single View iOS Application

How to Create Single View iOS Application

Creating single view application with hello word is easy with just a few steps. Below are described steps for starting up native application development in iOS with simple Hello word application.

  • Open Xcode from application folder or find it from finder & open it
  • Directly click create Project or select from file -> New -> Project
  • Now it will ask for to choose a template for the project. Select SingleView App & click next

Read more: How to Create and Setup a Prefix Header File for iOS

  • Next step is to set app name, bundle name & select Language. Check below screenshot.
  • In product name add your application name as you wish. It will be editable later on.
  • Select Team from a drop-down. By default, the team will be your system admin name
  • Type organization name. If you are an individual developer you can add your name or company name
  • Now the most important part is Language selection. Note that once you selected Language than it will not be editable later on. So it becomes more important to think about the future scope of the application & choose the language.
  • You can tick below check marks for Use core data & unit tests depending on required usage during the development. We will keep it unticked as it’s not required in the application right now
  • Once all fields fill up properly then click next.
  • Now it will ask to choose a path. Select location where you would like to save the project source
  • An application is now ready for the development you can start making simple controls on it & run it on a simulator for testing
  • Below the full video for creating simple single view hello word application
Share
Quick Tips to Speed up Macbook Like a Pro

Quick Tips to Speed up Macbook Like a Pro

Are you using MacBook or any other Mac system with development tools or developing apps? Then you may definitely get an issue with speed. Although usually Mac systems are configured with minimum 4 GB ram still it sometimes stucks while doing multitasking.

Consider a case while you are developing application & you will need to test the application on a simulator that will be a tidy process. You might do close unnecessary apps or sometimes have to even close the apps which you really need to keep open for making the system run smoothly.

We often consider open apps who takes more ram usage but we forget that there are some hidden activities which also consumes lots of memory & due to that system gets hanged or sometimes becomes unresponsive or stuck in the spinner loading.

 

There are few simple tricks you should try out to make your mac system runs smoother with just a couple of steps,

 

  • The first option is you have to check & understand the possible memory usage on your system. Like you are using advanced development tools like Xcode, Studio or Movie maker like tools requires more memory. So at the time its wise to upgrade your ram with at least 8 GB. That will be more than enough for run multitasking or developing tools run smoothly without any interruption.
  • If you think dashboard tools are not frequently used than remove it. To remove it go to System Preferences -> Mission Control -> Select Dashboard dropdown & make it off
  • If you are using the browser then close unnecessary tabs. Some of the sites with continues and flows may consume more memory usage & can slow down your system process
  • You can see which process is taking more memory from the Activity Monitor option. Find Activity Monitor from finder & open it. See below screenshot how it shows which process taking how much memory.

Read more: Important Tips to Test iPhone Application

  • Make sure keep your system updated with new updates provided by the apple. Keep all your software up to date. As new versions always release with the bug improvements so that might help your system to run smoothly
  • Keep removing cache files from browser & keep it clean as cache files consume lots of memory.
  • Remove unused or unnecessary files & folders from disk & keep disk clean
  • Keep the trash clean. Users often doing this mistakes by removing the files but not removing it permanently. So as it’s in the trash it will still consume your disk space so logically the file is still in your system but in a trash folder. So keep cleaning trash folder as well.
  • Don’t save any files directly on a desktop. Keep always all the files in the documents folder
  • Make sure you don’t have any apps in your application folder which are not in use at all. That takes unnecessary space on your disk.
  • Don’t use any visual effects. By default on mac visual effects are enabled. That doesn’t make any sense if you have memory issues. Its better you make it off. Go to System Preferences -> Dock & untick Magnification. Also, change Minimise effect from Genie to Scale.

There are lots of software available in the market which offers to clean mac system & remove junk files, spam from the system. But I suggest the best way is to do it manually. As these are the automated systems & sometimes at taking remove important system file & keep you in more trouble.

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
Share