Dismiss keyboard on tap outside textfield in Xcode 7.1

  • In viewDidLoad() function of your viewcontroller class copy paste the following code

var tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: "DismissKeyboard")
        view.addGestureRecognizer(tap)
  • Add a function
 func DismissKeyboard(){
        view.endEditing(true)
    }

Display timer and progress bar with AVAudioRecorder Swift

  • Drag and drop “Progress View” from the object Library into your view controller.
  • Link progress view with your view controller class.

    @IBOutlet weak var progressView: UIProgressView!


  • Add a label to your view controller and link it.

    @IBOutlet weak var recorderTimer: UILabel!

  • Declare a variable of type NSTimer in your view controller class.

var timer:NSTimer?

  • In viewDidLoad() function of your view controller class copy paste following code

        timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector:Selector("setProgress"), userInfo: nil, repeats: true)


  • Make a function setProgress()

  func setProgress() {

var seconds = (audioRecorder?.currentTime)

var time=String(format: "%0.0f sec",seconds!)

recorderTimer.text = time

var progresscounter:Double=(audioRecorder?.currentTime)!

progressView.progress=Float(progresscounter/10)

}

Deleting a Node in Linked List


	public Node deleteNode(Node head,int position){
		int size=length(head);
		if(position>size||position<1){
			System.out.println("Position invalid. Valid inputs are from 1 to "+size);
			return head;
		}
		if(position==1){
			Node currentNode=head.getNext();
			head=null;
			return currentNode;
		}else{
			Node previousNode=head;
			int count=1;
			while(count
	

Inserting a Node in Linked List


public Node InsertInList(Node head,Node nodeToInsert,int position){
		if (head==null) return nodeToInsert;
		int size=length(head);
		if(position>size+1||position<1){
			System.out.println("Position invalid. Valid inputs are from 1 to"+(size+1));
			return head;
		}
		if (position==1){
			nodeToInsert.setNext(head);
			return nodeToInsert;
		}else{
			Node previousNode=head;
			int count=1;
			while(count
	

Linked List Node


class Node{
	int data;
	Node next;
	public Node(int data){
		this.data=data;
	}
	public int getData(){
		return data;
	}
	public void setData(int data){
		this.data=data;
	}
	public Node getNext(){
		return next;
	}
	public void setNext(Node next){
		this.next=next;
	}
}


Find whether number is prime or not


import java.util.Scanner;

public class IsPrime {
	public static void main(String args[]){
		System.out.println("Enter a number");
		Scanner sc = new Scanner(System.in);
		int number=sc.nextInt();
		if(isPrime(number)){
			System.out.println("Number is Prime");
		}else{
			System.out.println("Number is not Prime");
		}
	}

	private static boolean isPrime(int number) {
		if(number<2)return false;
		for(int i=2;i<=Math.sqrt(number);i++){
			if(number%i==0) return false;
		}
		return true;
	}
}