Directory Image
This website uses cookies to improve user experience. By using our website you consent to all cookies in accordance with our Privacy Policy.

The Common Mistakes iOS Developers Don't Know They're Making

Author: Info Campus
by Info Campus
Posted: Nov 08, 2017

What's the main thing more regrettable than having a surrey application dismissed by the App Store? Having it acknowledged. Once the one-star surveys begin coming in, it's practically difficult to recuperate. This costs organizations cash and designers their occupations.

iOS is presently the second-biggest versatile working framework on the planet. It likewise has a high reception rate, with over 85% of clients on the most recent variant. As you may expect, exceedingly drew in clients have elevated standards—if your application or refresh isn't impeccable, you'll find out about it.

With the interest for iOS designers proceeding to soar, many specialists have changed to portable improvement (more than 1,000 new applications are submitted to Apple consistently). Be that as it may, genuine iOS skill reaches out a long ways past fundamental coding. The following are 10 normal mix-ups that iOS engineers fall prey to, and how you can keep away from them.

Normal Mistake #1: Not Understanding Asynchronous Processes

An exceptionally basic kind of slip-up among new developers is taking care of offbeat code disgracefully. How about we consider an average situation: User opens a screen with the table view, a few information is brought from the server and showed in a table view. We can compose it all the more formally:

@property (nonatomic, solid) NSArray *dataFromServer;

  • void)viewDidLoad {

__weak __typeof(self) weakSelf = self;

[[ApiManager shared] latestDataWithCompletionBlock:^(NSArray *newData, NSError *error){

weakSelf.dataFromServer = newData; //1

}];

[self.tableView reloadData]; //2

}

/and other information source designate strategies

  • NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

return self.dataFromServer.count;

}

At first look, everything looks right: We get information from the server and afterward refresh the UI. Be that as it may, the issue is bringing information is a nonconcurrent procedure, and won't return new information instantly, which implies reloadData will be called before getting the new information. To settle this error, we should move line #2 directly after line #1 inside the square.

@property (nonatomic, solid) NSArray *dataFromServer;

  • void)viewDidLoad {

__weak __typeof(self) weakSelf = self;

[[ApiManager shared] latestDataWithCompletionBlock:^(NSArray *newData, NSError *error){

weakSelf.dataFromServer = newData; //1

[weakSelf.tableView reloadData]; //2

}];

}

/and other information source assign strategies

  • NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

return self.dataFromServer.count;

}

Be that as it may, there might be circumstances where this code still does not carry on of course, which brings us to …

Normal Mistake #2: Running UI-Related Code on a Thread Other than the Main Queue

We should envision we utilized adjusted code case from the past regular mix-up, however our table view is still not refreshed with the new information even after the nonconcurrent procedure has effectively finished. What may not be right with such straightforward code? To comprehend it, we can set a breakpoint inside the shut and discover on which line this square is called. There is a high shot the portrayed conduct is occurring on the grounds that our call isn't in the fundamental line, where all UI-related code ought to be performed.

Most prominent libraries, for example, Alamofire, AFNetworking, and Haneke—are intended to call completionBlock on the principle line subsequent to playing out an offbeat undertaking. Notwithstanding, you can't generally depend on this and it is anything but difficult to neglect to dispatch your code to the correct line.

To ensure all your UI-related code is on the principle line, bear in mind to dispatch it to that line:

dispatch_async(dispatch_get_main_queue(), ^{

[self.tableView reloadData];

});

Regular Mistake #3: Misunderstanding Concurrency and Multithreading

Simultaneousness could be contrasted with a truly sharp blade: You can without much of a stretch cut yourself in case you're not cautious or sufficiently experienced, but rather it's to a great degree helpful and proficient once you know how to utilize it legitimately and securely.

You can attempt to abstain from utilizing simultaneousness, however regardless of what sort of applications you're working, there is truly high shot you can't manage without it. Simultaneousness can have critical advantages for your application. Outstandingly:

Practically every application has calls to web administrations (for instance, to play out some overwhelming estimations or read information from a database). In the event that these assignments are performed on the fundamental line, the application will solidify for quite a while, making it non-responsive. Also, if this takes too long, iOS will close down the application totally. Moving these errands to another line enables the client to proceed with utilize the application while the operation is being performed without the application seeming to solidify.

Present day iOS gadgets have more than one center, so for what reason should the client sit tight for assignments to complete successively when they can be performed in parallel?

Be that as it may, the upsides of simultaneousness don't come without many-sided quality and the potential for presenting gnarly bugs, for example, race conditions that are truly difficult to replicate.

We should think of some as certifiable cases (take note of that some code is excluded for straightforwardness).

Case 1

last class SpinLock {

private var bolt = OS_SPINLOCK_INIT

func withLock(@noescape body: () -> Return) -> Return {

OSSpinLockLock(&lock)

concede { OSSpinLockUnlock(&lock) }

return body()

}

}

class

}

set {

lock.withWriteLock {

_value = newValue

}

}

}

}

The multithreaded code:

let counter = ThreadSafeVar(value: 0)

/this code may be called from a few strings

counter.value += 1

on the off chance that (counter.value == someValue) {

/accomplish something

}

About the Author

Infocampus is the best Ios Swift Training Institute In Bangalore. Infocampus gives you real time and placement oriented Ios Swift training.

Rate this Article
Leave a Comment
Author Thumbnail
I Agree:
Comment 
Pictures
Author: Info Campus

Info Campus

Member since: Oct 09, 2017
Published articles: 26

Related Articles