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
Warning Function Var
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.
Use of string literal for Objective-C selectors is deprecated; use ‘#selector’ instead
Warning Selector
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.
‘++’ is deprecated: it will be removed in Swift 3
Warning ++
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.
C-style for statement is deprecated and will be removed in a future version of Swift
Warning For Statement
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]
__FILE__ is deprecated and will be removed in Swift 3, please use #file
This article is updated with Swift 4 – Xcode 9 – iOS 11
Why to use a library everytime? Slider Menu (Drawer) Let’s create our own Slide Menu (Drawer) in Swift 4. 1. Create New Project in Xcode 9 with Swift Language
2. Design the Menu in UIViewController Menu UIViewController
Declaration of Variables and Protocols (Delegate) :
Swift
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
protocol SlideMenuDelegate {
func slideMenuItemSelectedAtIndex(_ index : Int32)
}
class MenuViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
/**
* Array to display menu options
*/
@IBOutlet var tblMenuOptions : UITableView!
/**
* Transparent button to hide menu
*/
@IBOutlet var btnCloseMenuOverlay : UIButton!
/**
* Array containing menu options
*/
var arrayMenuOptions = [Dictionary<String,String>]()
/**
* Menu button which was tapped to display the menu
*/
var btnMenu : UIButton!
/**
* Delegate of the MenuVC
*/
vardelegate:SlideMenuDelegate?
}
Following method is for updating the Items in the Menu :
3. Now we will create a Base UIViewController to use anywhere in the project which control the delegate of menu.
First we will create this 3 lines Drawer Icon via Code
To open a view controller by identifier :
Set the Restoration Identifier and Storyboard Identifier. If current view is open then we will not open it once again for that we have to check via Restoration Identifier.
4. Now We will assign this drawer to any of the UIViewController
We have to use only one method to add drawer (slide menu) self.addSlideMenuButton()
Swift
1
2
3
4
5
6
7
importUIKit
classHomeVC: BaseViewController{
overridefuncviewDidLoad(){
super.viewDidLoad()
addSlideMenuButton()
}
}
Source Code is available at the Github AKSwiftSlideMenu GitHub AKSwiftSlideMenu Releases
You can download for versions of Swift 2, Swift 3 or Swift 4. From Releases Tab at GitHub AKSwiftSlideMenu.
I have uploaded a video for easy way to integrate AKSwiftSlideMenu in your project :
By giving you a simple example that we can not change the corner radius from the design view. We have to change it run time. If you want to make possible it with design time then you can use the @IBDesignable and @IBInspectable.
So, We are taking an example as IBButtonExtender for this the functionality
Border Color
Border Width
Corner Radius
Create an Custom Class for UIButton with @IBDesignable
Swift
1
2
3
@IBDesignable
classButtonExtender: UIButton{
}
Create an @IBInspectable for Inspect the element. the Border Color property will be added to the list in the right panel when you create button with this class.
Presenting the ButtonExtender for Border Color, Border Width and Corner Radius function with the @IBDesignable and @IBInspectable in the Swift Language.
By making some corner radius and colors, You will get neat and clean output. Output
Github
Find IBButtonExtender on github 🙂
Check other articles on Swift Language.
All suggestions are acceptable. Put it in the comments!
Happy Coding 🙂
In iOS 10 don’t forget to set capabilities (Keychain Sharing) : Go to your project targets -> Capabilities -> Keychain Sharing -> Toggle Switch ON Capabilities – KeyChain Sharing Detailed Output Log :