Thursday, November 17, 2016

How to reduce app size

There is App thinning concept which helps in reducing the size of the app.You can read a lot about it here

But as part of development,we developers can also do some part in reducing the app size.An easy way to reduce app size is using optimised images.Xcode does PNG compress if we use asset catalog.
PNGCrush is bundled along with Xcode to compress images whereas it cleans up unwanted chunks and recreates images so the size maybe bigger than original image.

Use imageoptim to optimise the images and then check the size of the app.

To Achieve best bundle size it is prefered to do following
  • Clean-Build-Archive-Export and note ipa file size.
  • Set "Compress PNG Files" to NO
  • Install Imageoptim (available at http://imageoptim.com/)
  • Go to terminal and navigate to source directory
  • Use command open -a ImageOptim .
  • It automatically looks into source for images and compress them (No worries optimizes images in .xcassets also)
  • Now ensure to wait for a while and let all progress indicators glow red
  • Clean and Build and Archive, You will observe resulting ipa file is far less than original.
  • Last but not least, thereafter when ever you add images into project just ensure to add the optimized ones. its as easy as dragging dropping images into imageOptim for optimisation.

    Refer:

    http://stackoverflow.com/questions/7388324/png-optimization-issue-using-pngcrush-tool/23361487

Thursday, July 14, 2016

JSON Parsing with Swift 2

We’ll look at how to parse a JSON array that we could use to display a list of items in a table view. More spefically, we’ll use the following JSON (copied and tweaked from David Owens II) to display a list of blog titles in our app.
Assuming we’ve made a request and received the JSON above, we just need to ask NSJSONSerialization to give us a JSON object, and then pull out the “blogs” and “name” keys. First, take a look at the full code, then we’ll break it down and explain it in smaller pieces:
Let’s break down what’s actually happening here.
First of all, everything is surrounded in a do/catch block since JSONObjectWithData:options: may throw an error. If you’re familiar with Objective-C, you’ll notice that we don’t pass in an NSError pointer here – instead, JSONObjectWithDatais marked with throws, meaning it may throw an error. The error that we catch (which is called error by default) replaces the NSError pointer from Objective-C.
Let’s look at the next line (with a bit of commentary added):
Here, we’re attempting to take "blogs" from the JSON, cast it to an array of dictionaries ([[String: AnyObject]]), and assign it to a constant called blogs. If all of that is successful, our if block will execute. (Aside: this if let syntax is called optional binding, and you need to understand it if you’re writing Swift. You can read about it in The Swift Programming Language.)
Moving on:
Here, we’re iterating through our array of blogs, and we know that blog is a dictionary of type [String: AnyObject] based on the type of our blogs array. Inside the for loop, we’re doing optional binding again to grab the name of the blog as a String, then appending it to our names array.

To read original article refer this link