Firebase Authentication gives us backend services to authenticate users with your app. It provides SDKs and ready-made UI libraries. It supports authentication using passwords, and other providers like Google, Facebook and Twitter, Github, and more.
swiftlang
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 π
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.
iOS 10 New Frameworks
- 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 :
Best Tweets of iOS 10 & Swift 3 Updates
Use a struct instead of a string as your dictionary key for better performance ? #swiftlang #WWDC16 pic.twitter.com/9ITOLwyHox
— NatashaTheRobot (@NatashaTheRobot) June 19, 2016
So excited about the Swift Performance session already!#WWDC16 #swiftlang pic.twitter.com/vJAjrAJJjN
— NatashaTheRobot (@NatashaTheRobot) June 19, 2016
You can now know when the user dismisses your notification ? #WWDC16 #iOS10 #iosdev
— NatashaTheRobot (@NatashaTheRobot) June 19, 2016
Media Attachments in Notifications ?? #WWDC16 #iOS10 #iosdev pic.twitter.com/o7EopfE9wg
— NatashaTheRobot (@NatashaTheRobot) June 19, 2016
Whoa! We can now access the users notification settings for our app ??? #WWDC16 #iOS10 #iosdev pic.twitter.com/8fo9faLA6T
— NatashaTheRobot (@NatashaTheRobot) June 19, 2016
Oooh #keyPath in Swift 3.0 ? #byebyestrings pic.twitter.com/E9mj9NH7al
— Ayaka Nonaka (@ayanonagon) June 18, 2016
Now that Iβve had some time to recover from WWDC, I highlighted some of my favorite ? 3.0 features. Hope you enjoy! https://t.co/hm77J2NZV3
— Ayaka Nonaka (@ayanonagon) June 19, 2016
replacement for the graphics context creation pic.twitter.com/687sZCsxoD
— Alejandro Martinez (@alexito4) June 19, 2016
Before and after of Core Graphics (old C API) in Swift thanks to compiler magic using NS_SWIFT_NAME in Swift 3.0! ? pic.twitter.com/uJYANo5wqU
— Ayaka Nonaka (@ayanonagon) June 18, 2016
Get Reactions from Timeline Post via Facebook Graph API – Swift – iOS
New version of SDK is 4.16.x(Swift) and Graph API Version is 2.8.
With the Graph API 2.6 Facebook has given support to fetch (read only) the Reactions on Timeline Posts.
Post is updated for iOS 10 and Swift 3
API documentation is available here.
Let’s learn how to get reactions from the post
Install pods
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 'FBSwiftLogin' do # Comment the next line if you're not using Swift and don't want to use dynamic frameworks use_frameworks! # Pods for FBSwiftLogin pod 'FacebookCore' pod 'FacebookLogin' end |
Login with Facebook
I have already written a tutorial on Facebook Login.
Get Facebook Posts via Graph API
We can get the Facebook post via graph API : /me/posts for that we have to add user_posts permission with login.
1 2 3 4 5 6 7 |
func getFacebookUserPosts() { FBSDKGraphRequest(graphPath: "/me/posts", parameters: nil, httpMethod: "GET").start(completionHandler: { (connection, result, error) in if (error == nil){ print(result) } }) } |
Get Reactions from one of the Post
We can get the Facebook post reactions via graph API : /{post-id}/reactions. We have to pass parameters like fields and summary as described in getReactions function.
Note : Here I am writing sample for only first post.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
func getFacebookUserPosts() { var strGraphPath : String = "" FBSDKGraphRequest(graphPath: "/me/posts", parameters: nil, httpMethod: "GET").start(completionHandler: { (connection, result, error) in if (error == nil){ print(result) let data = (result as! [String : Any])["data"] as! [[String : Any]] if(data.count > 0) { let strId = data[0]["id"] as! String strGraphPath = "/"+strId+"/reactions" self.getReactions(strGraphPath) } } }) } func getReactions(_ strGraphPath:String) { FBSDKGraphRequest(graphPath: strGraphPath, parameters: ["fields":"id, name, type", "summary":"total_count, viewer_reaction"], httpMethod: "GET").start(completionHandler: { (connection, result, error) in if (error == nil){ print(result) } }) } |
Response should be like
Type of reactions : NONE, LIKE, LOVE, WOW, HAHA, SAD, ANGRY
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 |
{ data = ( { id = ACCOUNT_ID; name = "NAME"; type = HAHA; }, { id = ACCOUNT_ID; name = "NAME"; type = LIKE; } ); paging = { cursors = { after = REFERENCE_ID; before = REFERENCE_ID; }; next = "NEXT_REFERENCE_LINK"; }; summary = { "total_count" = 56; "viewer_reaction" = NONE; }; } |
#Like #Share #React π π π
Happy coding π
Use of Operator Overloading with Swift
I was just going through the Swift document and I found that Swift allow to overload the operator just like as C++ Language. Objective-C doesn’t allow to overload the operator.
As swift document we can also say “Operator Functions”.
Let’s Overload ^ (XOR Operator) to make Power of the value
Function Prototype :
Declare function prototype with left hand side value and right and side value.
1 2 |
func ^(lhs: Int, rhs: Int) -> Int { } |
Operations in the function :
To make the power of the value we have to apply following operations
1 2 3 4 5 6 7 8 9 10 11 12 |
func ^(lhs: Int, rhs: Int) -> Int { if(rhs == 0) { return 1 } else { var result = lhs for _ in 1 ..< rhs { result *= lhs } return result } } |
Let’s try to use with the operator :
1 2 3 |
let a = 2^2 //4 let b = 2^4 //16 let c = 3^3 //27 |
Happy Coding π
Swift 2.2 Warnings and It's Solutions – Xcode 7.3
Xcode 7.3 came with Swift 2.2 Version. I just updated to Xcode 7.3 and found following warnings because of Swift version change.
List of warnings with it’s solution:
- ‘var’ parameters are deprecated and will be removed in Swift 3
- Use of string literal for Objective-C selectors is deprecated; use ‘#selector’ instead
- ‘++’ is deprecated: it will be removed in Swift 3
- C-style for statement is deprecated and will be removed in a future version of Swift
- __FILE__ is deprecated and will be removed in Swift 3, please use #file
Warning with:
[code language=”obj-c”]
func functionTest(var param:String) {
print(param)
}
[/code]
Solution:
[code language=”obj-c”]
func functionTest(param:String) {
print(param)
}
[/code]
If you want to update that variable inside the function then you have to create copy of that variable to do operations on that.
Warning with:
[code language=”obj-c”]
btn.addTarget(self, action: "functionName", forControlEvents: UIControlEvents.TouchUpInside)
[/code]
OR
[code language=”obj-c”]
btn.addTarget(self, action: Selector("functionName"), forControlEvents: UIControlEvents.TouchUpInside)
[/code]
Solution:
[code language=”obj-c”]
btn.addTarget(self, action: #selector(ViewController.functionName), forControlEvents: UIControlEvents.TouchUpInside)
[/code]
Apple Documentation : Added information about the #selector syntax for Objective-C selectors to the Selector Expression section.
Warning with:
[code language=”obj-c”]
var i = 0
for str in arrStr {
print(str)
i++
}
[/code]
Solution:
[code language=”obj-c”]
var i = 0
for str in arrStr {
print(str)
i += 1
}
[/code]
Apple Documentation : Removed discussion of C-style for loops, the ++ prefix and postfix operators, and the — prefix and postfix operators.
Warning with:
[code language=”obj-c”]
for var i=0; i<arrStr.count; i += 1 {
print(arrStr[i])
}
[/code]
Solution:
[code language=”obj-c”]
for i in 0 ..< arrStr.count {
print(arrStr[i])
}
[/code]
Warning with:
[code language=”obj-c”]
__FILE__
[/code]
Solution:
[code language=”obj-c”]
#file
[/code]
More swift tutorials/articles are available here.
Happy Coding π
Swift Resources #3
Swift Useful Resources:
- Top 100 Best Blogs for iOS Developers
- SwiftyStoreKit Lightweight In App Purchases Swift framework for iOS 8.0+ and OSX 9.0+.
- Sensitive Fresh look at work with gestures in Swift.
- NumberMorphView A label view for displaying numbers which can transition or animate using a technique called number tweening or number morphing.
- SwiftImageProcessing This project demonstrates how to do pixel operations in swift.
- Gifu High-performance animated GIF support for iOS in Swift.
Posted by @NatashaTheRobot in Issue No. 80
If I got time then I will try to post the Swift/Objective-C useful resources everyday.
Happy Coding π
Swift Resources #2 – for Animation
Swift Useful Animation Resources:
- Spring A library to simplify iOS animations in Swift.
- Animo Bring life to CALayers with SpriteKit-like animation builders
- Advance A powerful animation framework for iOS and OS X.
- CKWaveCollectionViewTransition Cool wave like transition between two or more UICollectionView
- EasyAnimation A Swift library to take the power of UIView.animateWithDuration(_:, animations:…) to a whole new level – layers, springs, chain-able animations and mixing view and layer animations together!
- Cheetah Easy animation library on iOS with Swift2
If I got time then I will try to post the Swift/Objective-C useful resources everyday.
Happy Coding π