Featured
-
How Regression Testing Detects Integral Errors In Business Processes
Humans are forever changing and evolving and so to
by kristina.rigina -
Get Display Banner Advertising Opportunity on FindNerd Platform
“Do you have a product or service that nee
by manoj.rawat -
Android O Released with Top 7 New Features for App Developers
Android was founded by Andy Rubin, Rich Miner, Nic
by sudhanshu.tripathi -
Top 5 Features That Make Laravel the Best PHP Framework for Development
Laravel is a free open source Web Framework of PHP
by abhishek.tiwari.458 -
Objective C or Swift - Which Technology to Learn for iOS Development?
Swift programming language is completely based on
by siddharth.sindhi
Tags
Providing Extra padding in UITextField
UITextField is an editable area where one can use to get input from user using keyboard.
We often come to a situation where extra padding is required from the left or right depending on requirement. Padding is already provided by UITextField...
Copy Paste in Swift
Apple provides the UIPasteboard class which enables the data to be shared within the app and with another app. To share data we can use pasteboards.
Here is the code snippet depicting how copy and Paste functionality can be achieved in...
Animating images in ImageView
ImageView can be used for animation with a set of multiple images using various properties offered by apple.
Here are I’m going to tell you steps to animate images in ImageView:
1- Initialise an array of UIIm...
NetworkReachability Listener in Alamofire
Alamofire provides a method to check network status reachable on WWAN, Ethernet and wifi. The NetworkReachabilityManager class provided by Alamofire listens whenever there is a change in network.
It can be used to determine background informat...
How to change voice using AVSpeechSynthesis in swift
This blog includes the use of -
AVSpeechSynthesisVoice
If we want to change the default voice i.e system voice then we need to use speechVoices{} array which contains the name of persons and locations. iOS has a nice method for sett...
Adding Properties to Attribute Inspector in Swift
Accessing properties via interface builder is quite easy and more developer friendly.
Here I’m guiding you how to to add new/custom properties to interface builder.
1- Subclass any UIObject, we are considering here UIButton ...
Function inside a function
Functions are small modules or chunk of code. Swift’s function syntax is so flexible that it allows to write a function inside a function.
Here is a syntax:
func firstFunction(arguments) -> returnType{
func secondFunction(arg...
TextToSpeech API provided by Apple
Apple has provided a powerful api to play audio from text and here are the steps to achieve:
1- Import AVFoundation framework
2- Initialise AVSpeechSynthesizer(as below)
let synthesizer = AVSpeechSynthesizer()
...
Bottom pull to refesh for pagination in table view in Swift
Hi Readers,
Pagination is required in most of our apps in today scenario. We can achieve it either pull to refresh from top or bottom. UIRefreshControl is the feature if you want to implement it from top side and insert processed records into ...
How to parse JSON in Swift with ObjectMapper
Hi Readers,
Every app needs to parse JSON data coming from server and ObjectMapper is a powerful tool to achieve that. It can be easily done with provided pod which can be install by adding following line into podfile:
pod 'ObjectMa...
Blocks or closures in Swift
Hi Readers,
We used to code blocks in Objective C, mainly to implement callbacks. For that particular functionality we can use closures in Swift. That will work same as blocks in Objective C. Closures are enclosed in curly braces { } and are d...
How to download videos from YouTube in iOS
Hi Readers,
We can download video file from Youtube if we know youtube URL of the video. First you need to add attached files (HCYoutubeParser) into your project. Now you need to call following function into your code:
let video = HCYout...
How to download data Using NSOperations and NSOperationQueue
Hi Readers,
It is sometimes required to download files or images from server into local. We can perform these tasks by NSOperation and NSOperationQueue efficiently. The basic idea is to create each download operation separately and add these o...
How to decode HTML string coming from server to iOS readable string
Hi Readers,
Many time we will get HTML content in our API response which we need to load into our component like UILabel. We can convert this HTML content into normal string or more specifically NSAttributed string which we can set into ...
How to cancel all request from Alamofire
Hi Readers,
If you are using Alamofire framework to implement API service classes and you need to cancel all the request which are fetching data from server. You can use following Swift code snippet:
if #available(iOS 9.0, *) {
...
Javascript function call in webview
Hello Readers,
In order to call javascript functions within webview,following code snippet may be used:
Specify path of the html file which contains the javascript function:
NSString *path;
NSBundle *bundle = [NSBundle mainBundle];
p...
Open Date picker on textField begin editing in Swift
To open a date picker in textFieldShouldBeginEditing we can use the inpuView property of the textField.
To open a datePicker when text Field start editing we can follow these steps.
1- On your View Controller add a view that contains the our ...
Adding Toolbar above keyboard
Hello Readers,
To add a toolbar above the keyboard we may use the following code snippet.
We will create a toolbar with the needed items and set as the input accessory View of the keyboard. In the below code we have added a done button on t...
Create a textField with left Side image and bottom border line in swift
1- Create a new class subclass of UITextField.
2 -Write down code below in new created class
3- Add a textField in ios Your viewController.
4- Chnage th class of your TextField with the new class that you created.
5- Change the attrib...
How to send a request with parameters in Alamofire
Alamofire is HTTP networking library for iOS and Mac OS X, which is written in swift. Alamofire is based on NSURLSession,but it make network code much easy to write.
Following function is available in Alamofire.
.upload
.down...
How to create your own search bar in Swift (Not using UISearchBar)
Here is a small example of custom search bar
1. Go to storyboard, take TextField place it at below navigation bar (we will type text here to find any string)
2. Set delegate of TextField
Come to ViewController class now
Create I...
UiSplitView Controller in Swift
To Create a SplitViewController in swift follow the steps:-
1- Create a new Project.
2- Add a splitViewController.
3- Create a cocoaTouch Class inherits from UIViewController named as DetailViewController
4- Create another CoCoatouchC...
Create a Singleton class in swift
Hi,
To Create a Singleton class in swift follow steps below:
1- Add a Cocoa Class file subclass of NSObject named it as MySingleton and now write down the code as .
import UIKit
class MySingleton: NSObject {
static let ...
How to shuffle an array
Hi all,
Shuffling an array means randomly re-arranging the content of an array .Shuffling algorithm can be used in many places now days like in card games, music player , media player etc.
Shuffling of an array can be done in two ways.
...
Tic-Tac-Toe
Hi all,
Tic-Tac-Toe is simple game in which you will try to mark your sign in three blocks to make a row , column or diagonal.
RULES FOR TIC-TAC-TOE
1. The game is played on a grid that's 3 squares by 3 squares.
2. You a...
How to add new .pch file to your Xcode Project?
From Xcode6 and later .pch file is not created automatically. One has to create it manually.
Following are the steps to add/create a pch file in your xcode project:
Create a new file using: cmd+N
• &nbs...
A simple function returning UIColor from HexaColor String in swift
Here are step-by-step guide to obtain UIColor:
1- Firstly you need to do is to remove all spaces and new line character sets from the string and then covert the string to UPPER Case example AABBCC.
var cString:String = hexColorString.stri...
AVAudioPlayer implementation in Swift
An easy to implement simple swift class working on AVAudioPlayer depicting various features like play, pause and stop.
// creating single instance of class
static let sharedInstance = MyAudioPlayer()
var myAudi...
UI Objects not visible in storyboard when changing height and width specifications
You may often come to a situation when your UIObject(say UIImageView) is not visible on storyboard.
It may be because you’ve dragged and dropped the UI Object for specification(say Regular Width - Regular Height) other than Any-Any.
&...
Protocols in Swift
Hi All,
Protocol : - A protocol defines a representation of methods and properties that suit a particular task or piece of functionality. The protocol can then be adopted by a class, structure, or enumeration to provide an actual implementatio...
Use vibrancy effect in UITableViewCell like notification center.
1. It is must to import “NoticationCenter” so that we can use “notificationCenterVibrancyEffect”
import NotificationCenter
2. At the time of cell selection do following code in delegate method...
Collapsable UITableView header in Swift
To collapse table header in swift ->
1. Make a property of NSMutableSet, name it "collapsedSections", this property will be use to check Collapsed section in the UItableViewCell.
var collapsedSections:NSMutableSet =...
How to give border color to UIButton in objc and Swift.
To give border color to UIButton :-
1. Take UIButton as property .
2. Give corner radius and corner width to UIButton.
3. Now give border color to UIButton.
For Swift use :-
demoButton.backgroundColor = UIColor.clearColor()
demo...
Two Way Binding in Swift
Hi All,
Two Way Binding :- In two way binding, data flows in both direction, from object to UI and vice-versa. For instance, you can have a UITextField called as nameTF which is binded with an object having property nameValue. So when the obj...
One Way Binding In Swift
Hi All,
One Way Binding :- In one way bindings, data flows only from object to UI and not vice-versa. For instance, you can have a UITextField called as nameTF which is binded with an object having property nameValue. So when the object value...
Auto Layout Using Visual Format Language In Swift
Hi All,
You can add auto layout constraints by using Storyboard Interface OR by adding constraints dynamically. There are three ways to add constraint dynamically (as per Apple Inc.)
Visual Format Language is one of the way is used to a...
Auto Layout Using NSLayoutConstraint In Swift
Hi All,
You can add auto layout constraints by using Storyboard Interface OR by adding constraints dynamically. There are three ways to add constraint dynamically (as per Apple Inc.)
NSLayoutConstraint is one of the way is used to add autol...
Adding auto layout constraint dynamically in swift
Hi All,
You can add auto layout constraints by using Storyboard Interface OR by adding constraints dynamically. There are three ways to add constraint dynamically (as per Apple Inc.)
Layout Anchor is one of the way is used to add autolayout...
NSTimer In Swift
Hi all,
You can use the NSTimer class to create timer objects or, more simply, timers. A timer can wait and call a method or selector after defined period of time. for example :- if you want show a seconds clock and stop when it completed 60 s...
How to print without newline in swift 2.0
Hi Readers!
In swift 2.0, print() statement adds a new line character automatically, where as in swift 1.2, println() and print() were 2 separate functions.
Apple in 2.0 has given only 1 statement for print() with different parameters.
T...
How to declare Sets in Swift
Hi Readers!
Let us first understand what Sets means.
Sets
A set stores unique values of same type in a collection with no ordering. Sets should be used when there is no defined order, such as in Array. Secondly Array can store multiple ...
Fetch the user detail from facebook in iOS 9.0
To fetcht the user detail from facebook like name,first_name,last_name,middle_name,gender etc use the code below :
func fetchUserDetails(useid: String,accessToken:String)
{
let graphRequest : FBSDKGraphRequest = FBSDKGraphRequest...
login to facebook in ios 9.0
to login using facebook in iPhone sdk please use the code below.
install the pods for facebook using
pod "FBSDKCoreKit";
pod "FBSDKLoginKit";
pod "FBSDKShareKit";
pod "FBSDKMessengerShareKit"
import FBSDKLoginKit
...
Send a request using Alamofire in swift
Use the alamofire in swift first install the pod file in your project using below steps:
1- open the terminal and run following commands
sudo gem update --system
sudo gem install cocoapods
pod setup
change folder to the current proejct ...
How to use completion handler in swift
The code below will help you in declaration of completion handler and how to call the completion handler in swift.
To declare a completion handler in swift use the line :
typealias completionHander = (sucess: Bool)->Void
//decalrat...
Change the button background color when highlighted in swift
To create a button at run time in swift please use the followin code:
this code will help you in creating a button at run time. and also change the background color of the button in highlihted State..
To change the button background at the tim...
How to create a UIAlertView in swift
Hello friends , To create UIAlertView in swift ->
UIAleartView is deprecated in iOS 9,
so you need to use UIAlertController instead .
let alertController = UIAlertController(title: test alert, message: this is a test alert, preferredS...
Show The Contact List in iOS
To show the list of contact in iPhone use the code Below:
1- import the ContactsUI framwork in viewController
2- Confrom the ViewController to the CNContactPickerDelegate
3- call the delegate method func contactPicker(picker: CNContactPicke...
Adding Blur effect in swift
Hello friends,
To add blur effect in swift you may use the following code:
IBAction func blurImage(sender: AnyObject) {
// 1 Create an object of UIBlurEffect,you may change the value of style as per your requirement
var darkBlur = UIB...
Chaneg Textview height according to text
Hi All,
If you want to change height of textView according to content height than you can follow this code.
Use auto layout to set view in story board and make IBOutlet for textview . Assign delegate to textview and dont give height constra...