How to set alternate icon for an iOS app programmatically?

Hello iOS Devs,
Hope you guys doing well in this COVID-19 situation. Stay Safe At Home.

In this week Xcode 11.4 released. Many new things came with that. You can check What’s new in Xcode 11.4? blog for the same.

App icon change functionality is available from iOS 10.3. In this tutorial we will learn to set an alternate icon for an iOS application programmatically.

Let’s Start!

Read more

How to use Alamofire with Codable in Swift?

Hello after long time I am writing this blog regarding use of Alamofire with Codable model object for the ease of MVC architecture.
Let’s rewind with some of the post which is used to cover this point:

  1. How to use Alamofire and SwiftyJSON with Swift?
  2. How to create a wrapper for Alamofire and SwiftyJSON?
  3. Use of Codable and Coding Key with JSONEncoder and JSONDecoder in Swift 4

Let see about use of Alamofire with Codable model object

Step 1 – Create Codable object based on JSON response.

Here I am taking an example of a web service which contains JSON related to the contact.

So, we can create two Codable files from this JSON as per hierarchy. These would be like as follows:

As you can see we have created 2 objects Contact and Phone. Here Phone is in sub hierarchy.

Step 2 – Let’s update AFWrapper

As we have previously revised blogs, there is a blog mentioned about to create a wrapper of the Alamofire and SwiftyJSON. We have to replace the SwiftyJSON code to return normal dictionary objects, and after that we will convert that dictionary to the Codable object.
So here I have updated the AFWrapper class file to do that thing:

Step 3 – Implement and convert the response in object

We will call a web service which contain that kind of JSON response. And after calling the web-service we will decode the object to create the Codable object.

In above sample I have added one text view in the view controller and I am fetching the data from the contacts API. After that using JSONSerialization and JSONDecoder we will get our decoded Contact object with Phone object.

Conclusion

Swift 4 comes with so many updates. We are going to have a great time exploring them all and finding out so much more by using it on further projects. We have learned about Codable and use of it. You too should go check it out and share your experiences with us in the comments section.
Hope you liked the article.
Happy Coding 🙂

Use of Codable and Coding Key with JSONEncoder and JSONDecoder in Swift 4

Codable is added with Xcode 9, iOS 11 and Swift 4. Codable is used to make your data types encodable and decodable for compatibility with external representations such as JSON.
Codable use to support both encoding and decoding, declare conformance to Codable, which combines the Encodable and Decodable protocols. This process is known as making your types codable.

Let’s Take an Example with Structure of Movie, here we have defined the structure as Codable. So, We can encode and decode it easily.

Read more

Firebase Remote Config [Swift]

Firebase Remote Config is used to change the application behavior without publishing update of application.

Firebase Remote Config
Firebase Remote Config

Basic setup is to create project at firebase console.
Firebase Console
Firebase Console – Follow the steps to create a project

I am adding a video here to setup the firebase remote config.

Add core firebase to your project

Follow the steps available at : Add Firebase to your iOS Project

Steps to add remote config to your app

  1. Installation
    Update your project with required cocoapods

    Run pod install from terminal and open the created .xcworkspace file.
  2. Configure Firebase Module
    Just import firebase module and apply configure method. It will configure by itself by using GoogleService-Info.plist.
  3. Configure remote config
    Create Remote Config object, as shown in the following example:

    Create an plist file for default values of configuration and set it to remote config:

    FireSwiftRemoteConfigDefaults.plist with sampleURL key:

    Use current default key from your defaults set on plist file and send fetch request in remote config to get the configuration keys set on the firebase console:

    Note : If in developer mode cacheExpiration is set to 0 so each fetch will retrieve values from the server. The default expiration duration is 43200 (12 hours).
  4. All Done.
    Sample code available at Github. There are many other things with firebase, I will try give update in next tutorials.

    If you like then Buy me a coffee ☕️

    Happy Coding 🙂

Push Notifications in iOS 10 [Swift]

Push Notification iOS 10 Swift
Push Notification iOS 10 Swift

The new framework called “UserNotifications” is introduced with iOS 10 SDK. The UserNotifications framework (UserNotifications.framework) supports the delivery and handling of local and remote notifications.

So, Let see what we have to change to get the push notifications in iOS 10.

Read more

Bye Bye to NS from Swift!!

Logo NeXTSTEP
Logo NeXTSTEP

Many of the types are bridged to the Swift type like as (e.g., NSString being bridged to String).
Other Objective-C types are bridged to Swift are as follows :

Objective-C Swift
NSString String
NSArray Array
NSDictionary Dictionary
NSData Data
NSError Error (Added Swift 3 – Xcode 8 Beta 4)
NSNotificationCenter NotificationCenter

And more…
Bye Bye to NS from Swift!!
Happy Coding 🙂

iOS 10 New Frameworks

iOS10

  • CallKit
    The CallKit framework (CallKit.framework) lets VoIP apps integrate with the iPhone UI and give users a great experience. Use this framework to let users view and answer incoming VoIP calls on the lock screen and manage contacts from VoIP calls in the Phone app’s Favorites and Recents views.
  • Intents
    The Intents framework (Intents.framework) supports the handling of SiriKit interactions.
  • IntentsUI
    The Intents UI framework (IntentsUI.framework) supports the creation of an Intents UI extension, which is an optional app extension that displays custom content in the Siri or Maps interfaces.
  • Messages
    To develop an iMessage app, you use the APIs in the Messages framework (Messages.framework) and To create app extensions that interact with the Messages app, allowing users to send text, stickers, media files, and interactive messages.
  • Speech
    Using the APIs in the Speech framework (Speech.framework), you can perform speech transcription of both real-time and recorded audio.
  • UserNotifications
    User Notifications framework (UserNotifications.framework), which supports the delivery and handling of local and remote notifications.
  • UserNotificationsUI
    User Notifications UI framework (UserNotificationsUI.framework) lets you customize the appearance of local and remote notifications when they appear on the user’s device.
  • VideoSubscriberAccount
    Video Subscriber Account framework (VideoSubscriberAccount.framework) to help apps that support authenticated streaming or authenticated video on demand (also known as TV Everywhere) authenticate with their cable or satellite TV provider.

References :