SwiftUI now support for Mesh Gradients.

Technology Makes A Wonderful World
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!
I found little snippet from twitter about how to know if application is installed via TestFlight.
Here, appStoreReceiptURL
is an instance property, which we can find from main bundle.
Here, I am adding snippet for both Objective-C and 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:
Here I am taking an example of a web service which contains JSON related to the contact.
1 2 3 4 5 6 7 8 9 10 11 12 |
{ "id": "c200", "name": "Ravi Tamada", "email": "ravi@gmail.com", "address": "xx-xx-xxxx,x - street, x - country", "gender" : "male", "phone": { "mobile": "+91 0000000000", "home": "00 000000", "office": "00 000000" } } |
So, we can create two Codable files from this JSON as per hierarchy. These would be like as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
struct Contact: Codable { var id : String var name : String var email : String var address : String var gender : String var phone : Phone } struct Phone: Codable { var mobile : String var home : String var office : String } |
As you can see we have created 2 objects Contact and Phone. Here Phone is in sub hierarchy.
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
import UIKit import Alamofire class AFWrapper: NSObject { class func requestGETURL(_ strURL: String, success:@escaping ([String : Any]) -> Void, failure:@escaping (Error) -> Void) { Alamofire.request(strURL).responseJSON { (responseObject) -> Void in print(responseObject) if responseObject.result.isSuccess { success(responseObject.result.value! as! [String : Any]) } if responseObject.result.isFailure { let error : Error = responseObject.result.error! failure(error) } } } } |
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
import UIKit class ViewController: UIViewController { var arrContacts = [Contact]() @IBOutlet var txtContacts: UITextView! override func viewDidLoad() { super.viewDidLoad() AFWrapper.requestGETURL("https://api.androidhive.info/contacts/", success: { (responseObject) in print(responseObject) for aContact in responseObject["contacts"] as! [Any] { do { let jsonData = try JSONSerialization.data(withJSONObject: aContact, options: .prettyPrinted) let reqJSONStr = String(data: jsonData, encoding: .utf8) let data = reqJSONStr?.data(using: .utf8) let jsonDecoder = JSONDecoder() let aContact = try jsonDecoder.decode(Contact.self, from: data!) self.arrContacts.append(aContact) self.txtContacts.text = self.txtContacts.text + aContact.name + " " + aContact.phone.mobile + "\n" print(self.arrContacts) } catch { } } }) { (error) in print(error.localizedDescription) } } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } } |
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.
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 🙂
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.
Firebase Remote Config is used to change the application behavior without publishing update of application.
Basic setup is to create project at firebase console.
I am adding a video here to setup the firebase remote config.
Follow the steps available at : Add Firebase to your iOS Project
1 2 3 4 5 6 7 8 9 |
# Uncomment the next line to define a global platform for your project platform :ios, '9.0' target 'FireSwiftRemoteConfig' do # Comment the next line if you're not using Swift and don't want to use dynamic frameworks use_frameworks! # Pods for FireSwiftRemoteConfig pod 'Firebase/Core' pod 'Firebase/RemoteConfig' end |
1 2 3 4 5 6 7 8 9 10 11 |
import UIKit import Firebase @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { // Firebase Configuration FIRApp.configure() return true } } |
1 2 3 4 5 |
var remoteConfig: FIRRemoteConfig! override func viewDidLoad() { super.viewDidLoad() remoteConfig = FIRRemoteConfig.remoteConfig() } |
1 2 3 |
let remoteConfigSettings = FIRRemoteConfigSettings(developerModeEnabled: true) remoteConfig.configSettings = remoteConfigSettings! remoteConfig.setDefaultsFromPlistFileName("FireSwiftRemoteConfigDefaults") |
1 2 3 4 5 6 7 8 |
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>sampleURL</key> <string>http://google.com</string> </dict> </plist> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
func fetchConfiguration() { lblResult.text = remoteConfig[sampleURLConfigKey].stringValue var expirationDuration = 3600 if remoteConfig.configSettings.isDeveloperModeEnabled { expirationDuration = 0 } remoteConfig.fetch(withExpirationDuration: TimeInterval(expirationDuration)) { (status, error) -> Void in if status == .success { print("Config fetched!") self.remoteConfig.activateFetched() } else { print("Config not fetched") print("Error \(error!.localizedDescription)") } lblResult.text = remoteConfig[sampleURLConfigKey].stringValue } } |
All Done.
Sample code available at Github. There are many other things with firebase, I will try give update in next tutorials.
Happy Coding 🙂
Xcode 8.0 comes with a Swift Migrator tool that helps you migrate your project to Swift 3, or update it to work with Swift 2.3 and the new SDKs.
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.
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 🙂