WWDC June 2017 | Keynote

  • tvOS: Introduced Amazon prime video Integration with Apple tvOS.

    Screen Shot 2017-06-05 at 10.45.41 PM.png

  • Apple Watch: watchOS 4 released with lots of amazing features like Apple watch Siri faces (upcoming events and weather, traffic. integration of AI make it more confident and accurate), cloudy displays and more mickey characters. Also they have Enhances lots of Apps like  Workout: High intensity training, Music For Siri.
  • macOS High Sierra: All about deep technology, lots of refinements in safari like auto play blocking, Intelligent tracking prevention. Refinements in Mail, Photos (Filtering, Face recognition(sycn across all devices, Photo editing tools)). Apple file system for macOS introduced its,  H265 new standard for videos. Metal 2 for graphics, video cut pro. Steam VR SDK – 90 frames per seconds for desining new VR expereice,  thunderbold 3.Screen Shot 2017-06-05 at 11.21.45 PM.png
  • iOS: iOS 10 – 96% customer satisfaction, 86% running installed base. Screen Shot 2017-06-05 at 11.39.12 PM.pngLaunch of iOS 11, Redesigned App drawers for messages app, integration with iCloud, End to end encryption. Apple Pay – Person to person payment also intrgarion with iMessage App. Apple Pay Card for holding your money. Siri – 375 million devices, Translation Beta. Camera – 1 Trillion photo per year. entrily new app store,Screen Shot 2017-06-05 at 11.38.07 PM.pngScreen Shot 2017-06-05 at 11.40.22 PM.png

    Introducing new ARKit for iOS.

    Screen Shot 2017-06-06 at 12.05.24 AM.png

  • iPad: 10.5 inch new iPad Pro with weight 1 pound, higher refresh rates, 40% faster graphics performance, multi touch, Files app for accessing all files with in the mac.Screen Shot 2017-06-06 at 12.17.13 AM.pngScreen Shot 2017-06-06 at 12.23.21 AM.png
  • Music: reinvent home music, Launch of HomePod, Musicologist. Screen Shot 2017-06-06 at 12.48.40 AM

Swift Code Snippets | Save Developer Hours

Do you write hundreds lines of code everyday ? And would you like to save ? Well than, code snippet libray may help you here.

The Concept of code snippets is saving a piece of code which we write very often. so now we can save it as snippet and use it quickly with shortcuts or drag & drop.

Here it is in IDE.

Screen Shot 2017-05-30 at 9.11.33 PM.png

How to build A Custom Snippet ?

By default, Xcode provides serval snippets and let add our own.

  1. Select the code which you want to create as snippet.
  2. Just drag and drop inside the Snippet option.

ima.png

we can also Edit Custom Snippet, Give the title and summary to our snippet, Completion Shortcut is what i like most its just give short name, define the scope, if its no longer required just select and delete it.

 

 

 

Swift | No Main Method | No Entry Point | iOS App

That is interseting to see, there is no main() for swift iOS project.

Because Cocoa Touch uses the @UIApplicationMain attribute (for Cocoa its @NSApplicationMain) to indicate that it is the application delegate, Using this attribute is euqivalent to calling UIApplicationMain function and passing the class name of the delegate class.

If you do not use this attribute, than supply a main.swift file with code at top level that calls the UIApplicationMain(_:_:_:_:) it means if you app uses custom subclass of UIApplication as its principle class, call the UIApplicationMain(_:_:_:_:) function instead of using this attribute.

Objective C Days | Memory Management |Short Note to Brush up

Summary

Lets see the traditional C ways for clearing up of unused objects is bit of a nightware. There is no ways in the language like how should be approached.

Imagine one function A create one object and pass it to another function B now both are using the same data now the problem is who is the responsible for deleting it, if its no longer used ? and lets say we have one function who is also gonna use the same data than what ?

Solution is there are conventions and design patterns to handle these situations,  that’s the reason the reference counting was developed and management technique used in Obj-C.

What we have in Obj-C

Obj-C uses reference counting as its Memory Management Technique so according to that each object keeps an internal count of how many times its needed.  So only incase of, if count drops to zero. Yes you can compare it with Garbage Collector we have in Java but its not like automatic some chunk of code getting executed and removing the objects which ones are not needed.

Ownership

Most important thing is Object Ownership it means an object owner is someone that has explicitly said “I need that object, do’t delete”. So one object can have more than one owner.

If object owner are not using it they have the responsibilty to tell so that the reference count should be decreased by one. So while dealing with Obj-C pointers/Objects its really good to send correct messages.

Messages

alloc, it will allocates an fresh instance of the object, set the reference count +1.

new, shortest way to write alloc&init.

retain, you passed the object and you want to tell you need that so its reference count should be increased by 1 again.

autorelease, need object temporarily and want to delete once you done with the operations.

copy, creates new copy of the object.

dealloc, opposite of init method, automatically get called right before the object is destroyed.

 Convenience Methods

Static methods used for allocating the initializing objects directly but be aware that you are not the owner of that object, once the scope of your program finish it will be removed.  Ex: [NSString stringWithFormat:@”Say %@”,@”Hello”];

Autorelease Pools

Its an instance of NSAutoreleasePool, objects which are to be autoreleased. You can also send message to autorelease or create object using convenience methods. So once the object added into autorelease pool and when the pool is popped, all the objects will be deleted.

Retain Cycles

Retain cycle is a condition where two objects strongly maintains a reference of each other and stops each other from being released. For example, let we have two classes as.

@interface Parent : NSObject
@property (nonatomic, strong) Child *child;
@end

@implementation Parent
@end

@interface Child : NSObject
@property (nonatomic, strong) Parent * parent;
@end

@implementation Child
@end

So, at some point of time when creating object of any of these class as

Parent *parent = [[Parent alloc] init];
Child *child = [[Child alloc] init];
parent.child = child;
child.parent = parent;

Here the parent object maintaining a strong reference of Child class and child object maintaining a strong reference of Parent class in back. So, both parent and child objects having a reference count of one and one. Both objects will get released from memory only when their reference count will reach to zero but in this scenario this will not going to happen ever because both are mutually pointing to each other a dead lock is get created here. This situation is called the Retain Cycle that will lead to memory leaks.

Fortunately, it’s very easy to fix this problem—just tell one of the properties to maintain a weak reference to the other object so, what’s this weak and strong reference means??

Strong Reference: A strong reference says that don’t release this object till I m owing this.

Weak Reference: A weak reference says that don’t release this object until someone else pointing this strongly.

Just like strong and __strong, weak and __weak keywords are there for declaring properties and instance variables respectively as a weakly referenced object.

Quick Tips and common mistakes

Think about strong and weak pointers as well as retain cycles, Avoid unnecessary caching, Don’t declare every object  globally unnecessarily, use Xcode Instruments such as static analyser and find the potential memory leaks and fix them

Arrays, Dictionaries and other objects that contains any object generally retain objects once you add it into them. It means once you create an object the reference count will be 1 and once you add it into an Arrays it wll be 2.

Releasing the Object that you do’t Own, lets say if creating an new object using convenience method than there is no need to release that.

Keeping and using an Object that you do’t Own.

Calling dealloc directly. So never call dealloc by the way you have to call init after calling alloc its kinda default constructor for init the default value of object.

Over-releasing. Accidentally you’re releasing something twice instead of once. You can also track these crashes by just enabling Zombies.

Retain Cycles. When an object released there is cascading effect, the root object released its childrens as well and so on. Lets say there is some condition like A owns B and B owns A as they own each other.

iOS | Bounds vs Frame ?

Everyone talk about bounds and frame during the interview for sure. lets make it little easy.

The Bounds of a view is recentagle, expressed as location coordinates (x,y) and also the size (height, width) relative to the own coordinate system.

The Frame of a view is recentagle, expressed as location coordinates (x,y) and also the size (height, width) relative to the its superview.

So for example lets say if you have UILabel on top of your UIView that has size of (100×100) with thelocation coordinates (10,10). so here is the Swift code.

override func viewDidLoad() {
        super.viewDidLoad()

        //Bounds
        print("label.bounds.origin.x    = \(label.bounds.origin.x)")
        print("label.bounds.origin.y    = \(label.bounds.origin.y)")
        print("label.bounds.size.height = \(label.bounds.size.height)")
        print("label.bounds.size.width  = \(label.bounds.size.width)")

        //Frame
        print("label.frame.origin.x    = \(label.frame.origin.x)")
        print("label.frame.origin.y    = \(label.frame.origin.y)")
        print("label.frame.size.height = \(label.frame.size.height)")
        print("label.frame.size.width  = \(label.frame.size.width)")
    }

So for the both cases size(height, width) will be same only the position (x,y) will be different as in case of bounds its relative to its own view and for frame its relative to superview. for more please see the below image(source: slideshare, CS 193P lecture).

Screen Shot 2017-05-17 at 11.12.59 AM

iOS Concurrency | Introduction | Options

Concurrency is two sided-weapon, that you should master and learn how to use because it will help you to write efficient code with fast execution but if you are misusing it, than results will be poor app performance, crashes etc.

So before writing code think about the problem, why do we need that and which API do you need to resolve it.

In iOS, we have different APIs that we can be used. But wait here the question is why do we need Concurrency ?

  • Utilize iOS Hardware: Now all of the iOS devices are with multi-core processors that allow developers to execute multiple tasks parallel. So here we can earn lots of benefits.
  • Better User Experience: Code for call multiple web services, handle IO and some heavy tasks etc will freeze UI and make your app non responsive so if as a user i face this i will close the app for sure, but with concurrency all tasks can be done in background without hanging the main thread.
  • APIs like NSOperation and Dispatch Queues makes it really easy: Earlier creating and managing threads are not easy that’s the reason everyone get scared when they hear about concurrency. Another major advantage of APIs is, it will also help you to manage synchronization to avoid the race condition, it happens with two threads try to access shared resource.