Use of constant (#define) in Swift Language – iOS

Swift Constant Test
Swift Constant Test

In Objective-C we are using a header file to create constant variables like as

// Objective-C
#define APP_ALERT_TITLE "Objective-C Constant"

Swift has new syntax to define the constant (#define)

// Swift
let APP_ALERT_TITLE = "Swift Constants"

Lets try

Create a swift file with the constants

import Foundation

class Constants {
    // MARK: List of Constants
    static let APP_ALERT_TITLE = "Swift Constants"
    static let SAMPLE_MESSAGE = "The alert is working !!"

Note : Here the MARK statement is also changed.

// Objective-C
#pragma mark -
#pragma mark List of Constants
// Swift
// MARK: List of Constants

Continue reading

How to use Alamofire and SwiftyJSON with Swift? – Swift 3 – iOS 10 – Xcode 8

Swift JSON
Swift JSON

Alamofire is an HTTP networking library written in Swift.
SwiftyJSON makes it easy to deal with JSON data in Swift.
Continue reading

Create your own Slider menu (Drawer) in Swift

This article is updated with Swift 4 – Xcode 9 – iOS 11

Why to use a library everytime?

Slider Menu (Drawer)
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
Menu UIViewController

Declaration of Variables and Protocols (Delegate) :

Following method is for updating the Items in the Menu :

Following method is for click event and animation :

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


Delegate (Protocol) method call :

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()

Source Code is available at the Github AKSwiftSlideMenu

GitHub AKSwiftSlideMenu Releases
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 :

Check other blog posts about Swift

Happy Coding 🙂

How to work with IBDesignable and IBInspectable in Swift Language?

IBDesignable with Storyboard
IBDesignable with Storyboard

How to use the @IBDesignable and @IBInspectable?

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

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.

Set Initialization functions and other @IBInspectable as above.

You can check the code for the ButtonExtender.swift


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.



Find IBButtonExtender on github 🙂

Check other articles on Swift Language.

All suggestions are acceptable. Put it in the comments!

Happy Coding 🙂