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.
What's new in Xcode 8.3?
Swift 2.3 Deprecation
- Xcode 8.3 beta 2 no longer supports Swift 2.3. Please migrate your projects containing Swift 2.3 code to Swift 3 syntax by opening the project and choosing Edit > Convert > To Current Swift Syntax.
Other Deprecations and Removal Notices
- The Automation instrument has been removed from Instruments. Use Xcode’s UI Testing in its place.
Organizer
- The Xcode Organizer now supports exporting tvOS apps for Enterprise distribution.
Testing
- Added the XCUISiriService class to XCTest for writing tests which activate Siri with a voice recognition string, and queries for elements in the Siri UI. Use the class to write UI tests for Intents and Intents UI extensions.
Swift Compiler
- The Swift compiler can now automatically precompile Objective-C bridging headers, which can speed up Debug configuration builds (or other non-WMO builds) of mixed-source projects with large bridging headers. This feature is still experimental, and is disabled by default but can be enabled with the “Precompile Bridging Header” (SWIFT_PRECOMPILE_BRIDGING_HEADER) build configuration setting within Xcode.
Provisioning
- Changed the user interface for managing signing certificates and provisioning profiles. Certificates are managed from the Accounts preferences pane by selecting a team and clicking Manage Certificates. Automatically managing signing is recommended, however if your app requires manually signing provisioning profiles are managed in the General tab of the project editor. Use the Provisioning Profile dropdown to import or download profiles. In addition it displays profiles that match the current signing configuration of the target.
Simulator
- You can invoke Siri using Hardware > Siri after enabling Siri in the Settings app on Simulator.
Others
- Xcode 8.3 includes Swift 3.1 which is intended to be source compatible with Swift 3.0.
- Constrained extensions allow same-type constraints between generic parameters and concrete types. For example, the following code defines an extension on Array with Int elements:
1extension Array where Element == Int { } - The Swift compiler now raises an error for modifications of a let property or variable of protocol type after initialization. For example, the following code that compiled in previous versions will now raise an error:
1234567891011protocol P {mutating func f()}extension Int: P {mutating func f() { self += 1 }}func foo(x: Int) {let y: Py = xy.f()}Code that successfully compiled in previous releases may fail after upgrading.
Interface Builder
- NSTextField objects created in Interface Builder now have allowsCharacterPickerTouchBarItem turned off by default.
Currently latest beta version is Xcode 8.3 Beta 3. I will update this blog as per versions of Beta.
Happy Coding 🙂
SwiftGoingFaster by Precompiled Bridging Headers
Faster Mix-and-Match Builds with Precompiled Bridging Headers
PROBLEM :
Every time a Swift file in a mixed-language target is compiled, the Swift compiler parses the project’s bridging header in order to make Objective-C code visible to Swift code. When the bridging header is large and the Swift compiler runs many times – as in a debug configuration – the cost of repeatedly parsing the bridging header can be a substantial part of the overall build time.
In Swift 3.1, you can reduced debug build time by 30% by using the new -enable-bridging-pch Swift flag for this issue. This mode is still experimental and must be manually enabled, but it will be enabled by default if developer feedback indicates it’s working well and providing significant speedup… so try it out!
Related Link : Faster Mix-and-Match Builds with Precompiled Bridging Headers
Happy Coding 🙂
Firebase Remote Config [Swift]
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.
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
- Installation
Update your project with required cocoapods
123456789# Uncomment the next line to define a global platform for your projectplatform :ios, '9.0'target 'FireSwiftRemoteConfig' do# Comment the next line if you're not using Swift and don't want to use dynamic frameworksuse_frameworks!# Pods for FireSwiftRemoteConfigpod 'Firebase/Core'pod 'Firebase/RemoteConfig'end
Run pod install from terminal and open the created .xcworkspace file. - Configure Firebase Module
Just import firebase module and apply configure method. It will configure by itself by using GoogleService-Info.plist.
1234567891011import UIKitimport Firebase@UIApplicationMainclass AppDelegate: UIResponder, UIApplicationDelegate {var window: UIWindow?func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {// Firebase ConfigurationFIRApp.configure()return true}} - Configure remote config
Create Remote Config object, as shown in the following example:
12345var remoteConfig: FIRRemoteConfig!override func viewDidLoad() {super.viewDidLoad()remoteConfig = FIRRemoteConfig.remoteConfig()}
Create an plist file for default values of configuration and set it to remote config:
123let remoteConfigSettings = FIRRemoteConfigSettings(developerModeEnabled: true)remoteConfig.configSettings = remoteConfigSettings!remoteConfig.setDefaultsFromPlistFileName("FireSwiftRemoteConfigDefaults")
FireSwiftRemoteConfigDefaults.plist with sampleURL key:
12345678<?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>
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:
1234567891011121314151617func fetchConfiguration() {lblResult.text = remoteConfig[sampleURLConfigKey].stringValuevar expirationDuration = 3600if remoteConfig.configSettings.isDeveloperModeEnabled {expirationDuration = 0}remoteConfig.fetch(withExpirationDuration: TimeInterval(expirationDuration)) { (status, error) -> Void inif status == .success {print("Config fetched!")self.remoteConfig.activateFetched()} else {print("Config not fetched")print("Error \(error!.localizedDescription)")}lblResult.text = remoteConfig[sampleURLConfigKey].stringValue}}
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).
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 🙂
Refined API Naming : Migrating to Swift 3!
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.
Push Notifications in 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.
Push Notifications in iOS 10 [Objective-C]
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.
Steps for implement code to handle push notifications in iOS 10
Import UserNotifications.framework in your AppDelegate file
1 |
#import <UserNotifications/UserNotifications.h> |
Also add UNUserNotificationCenterDelegate.
1 2 3 4 |
#import <UserNotifications/UserNotifications.h> @interface AppDelegate : UIResponder <UIApplicationDelegate,UNUserNotificationCenterDelegate> @end |
Register for push notification
Before registration check the version of iOS and then based on versions do the code. For iOS 7 code was different, fro iOS 8 & 9 code was different and again for iOS 10 code is different.
As per my opinion you have to set the deployment target to iOS 8 or iOS 9 and later. For this you can check the adoption ratio of iOS in the devices.
Define constant for version check :
1 |
#define SYSTEM_VERSION_GRATERTHAN_OR_EQUALTO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending) |
Add code in your did finish launching
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ [self registerForRemoteNotifications]; return YES; } - (void)registerForRemoteNotifications { if(SYSTEM_VERSION_GRATERTHAN_OR_EQUALTO(@"10.0")){ UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; center.delegate = self; [center requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error){ if(!error){ [[UIApplication sharedApplication] registerForRemoteNotifications]; } }]; } else { // Code for old versions } } |
Handling delegate methods for UserNotifications
You will be surprise that notification displayed when application in foreground too in iOS 10. As we know that in old versions we display alert or something else which will be look like notification comes in foreground.
There are two delegate methods need to be handled :
1 2 3 4 5 6 7 8 9 10 11 |
//Called when a notification is delivered to a foreground app. -(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler{ NSLog(@"User Info : %@",notification.request.content.userInfo); completionHandler(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge); } //Called to let your app know which action was selected by the user for a given notification. -(void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)())completionHandler{ NSLog(@"User Info : %@",response.notification.request.content.userInfo); completionHandler(); } |
Add Push Notifications Entitlements
Go to your project target’s Capabilities tab and add Push Notifications Entitlements.
If it’s available in your certificates then it will enable directly else configure your profile with the certificates and you can enable this capability by that.
All Done!
Happy Coding ?
I have added sample code of objective-c on github with iOS 8, 9 and 10 support of push notification.
I have also posted about Push Notifications in iOS 10 [Swift].
Steps to use Legacy Swift in Xcode 8
Xcode 8.0 is released with Swift 3 and Swift 2.3 compatibility.
If you already having a project with Swift 2.2 language support with Xcode 7.3.1 and you open the project in Xcode 8.0 then, you will be prompted for the migration assistant to do a migration pass. The assistant can also be invoked manually from the menu Edit -> Convert -> To Current Swift Syntax…
- Use Swift 2.3 Modifies your project to enable the Use Legacy Swift build setting and provides source changes to be able to build against the new SDKs.
- Use Swift 3 This is recommended. You will get source changes to be able to build your project using Swift 3 and take advantage of all the new features in Xcode 8.0.
If you want to work with new project and you want to work with Legacy code (Swift 2.3) or 3.0 then you can do settings from build settings as follows :
Default Setting is No (Swift 3). But if you want to do legacy code (Swift 2.3) then you have to select Yes (Swift 2.3).
Make sure you do this setting by starting of new project because many methods will change.
For Example :
Swift 3 Code
[code language=”obj-c”]
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}
[/code]
Swift 2.3 Code
[code language=”obj-c”]
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool {
return true
}
[/code]
As per my opinion Swift 3 is recommended.
Happy Coding 🙂
App Store Improvements : Apple will start the process of evaluating apps, removing apps that no longer function as intended from September 7, 2016
App Store Improvements
We love helping customers discover innovative, useful, and exciting apps on the App Store. With more than 2 million apps available and around 100,000 new and updated apps submitted each week, there’s something for everyone. To make it easier for customers to find great apps that fit their needs, we’re implementing two suggestions from the developer community starting September 7, 2016.
Quality Apps
Quality is extremely important to us. We know that many of you work hard to build innovative apps and update your apps on the App Store with new content and features. However, there are also apps on the App Store that no longer function as intended or follow current review guidelines, and others which have not been supported with compatibility updates for a long time. We are implementing an ongoing process of evaluating apps for these issues, notifying their developers, and removing problematic and abandoned apps from the App Store.
Shorter App Names
Search is one of the most frequently used methods for customers to discover and download apps from the App Store. In hopes of influencing search results, some developers have used extremely long app names which include descriptions and terms not directly related to their app. These long names are not fully displayed on the App Store and provide no user value. App names you submit in iTunes Connect for new apps and updates will now be limited to no longer than 50 characters. You can learn more about creating effective app names, as well as icons, keywords, screenshots, and descriptions, by reading the App Store Product Page.
To make it easier for customers to find great apps that fit their needs, we want to ensure that apps available on the App Store are functional and up-to-date. We are implementing an ongoing process of evaluating apps, removing apps that no longer function as intended, don’t follow current review guidelines, or are outdated.
What to Expect
When will this process start?
We will begin the process of reviewing and removing apps from the App Store on September 7, 2016.
What types of apps will be affected?
Apps in all categories on the App Store will be evaluated to make sure they function as expected, follow current review guidelines, and are not outdated.
What will happen if an issue is found with my app?
The App Store team will contact you and ask you to make any necessary changes for your app to stay on the App Store. However, apps that crash on launch will be removed immediately from the App Store.
How long do I have to make the changes?
You will be asked to submit an update within 30 days to keep your app on the App Store. If you are unable to make the changes within this time frame, your app will be removed from the App Store until you submit an update and it is approved. Please note that apps that crash on launch will be removed immediately.
If my app is removed, will my app’s name become available for other developers to use?
No. When apps are removed from the App Store, they are not deleted from your account. Your app name will continue to be associated with your app.
If my app is removed, will current users be able to access my app?
Yes. Your app will remain fully functional for current users. They will experience no interruption to services and will still be able to buy in-app purchases. However, we recommend that you update your app as soon as possible to reinstate it on the App Store and ensure that it remains functional and engaging for new and existing customers.
What can I do to help my app be ready for future changes?
As a best practice, read the latest App Store Review Guidelines as they are published and make sure your apps follow them. We also recommend that you address any functionality issues and update your app regularly to fix bugs, offer new content, provide additional services, or make other improvements. If you are no longer updating your app, consider removing it from the App Store.
Reference From : Apple News