Create a stack using ArrayDeque.Deque s = new ArrayDeque(); // stack s.push("Bat"); s.push("Mat"); s.push("Cat"); s.push("Rat"); s.push("Hat"); s.push("Fat");Create a queue using ArrayDeque −Deque q = new ArrayDeque(); // queue q.add("Bat"); q.add("Mat"); q.add("Cat"); q.add("Rat"); q.add("Hat"); q.add("Fat");The following is an example.Example Live Demoimport java.util.ArrayDeque; import java.util.Deque; public class Demo { public static void main(String args[]) { Deque s = new ArrayDeque(); Deque q = new ArrayDeque(); // stack s.push("Bat"); s.push("Mat"); s.push("Cat"); s.push("Rat"); s.push("Hat"); s.push("Fat"); ... Read More
To remove the border from a navigation bar in swift, we just need to add a few lines of code. Let’s see how the navigation bar looks when we run it without changing anything.Now let’s try to hide the line/ border shown in the above result.The navigation bar has two things that give it the default view of a grey shadow along with bottom line as shown above. One is the background image, and the other is the shadow image.First, we’ll hide the shadow image, by setting it to empty image and see how it looks.In your viewDidLoad add the ... Read More
To use collection view in swift, first, we need to create a collection View. We can either drag and drop it to the storyboard, or we can make it programmatically. After that, we need to confirm our class to UICollectionViewDataSource and UICollectionViewDelegate. Also if we need custom cell size and layouts, we need to confirm it to UICollectionViewDelegateFlowLayout.Let’s see the step required to create a collection View programmatically.func initCollection() { let layout = UICollectionViewFlowLayout() layout.itemSize = CGSize(width: 50, height: 50) let collection = UICollectionView.init(frame: self.view.frame, collectionViewLayout: layout) collection.dataSource = self collection.delegate = self collection.backgroundColor ... Read More
To create a dialog box in swift we’ll make use of UIAlertController which is an important part of UIKit. We’ll do this with help of an iOS application and a sample project.First of all, we’ll create an empty project, then inside its default view controller, we’ll perform the following operations.We’ll create an UIAlertController object.let alert = UIAlertController.init(title: title, message: description, preferredStyle: .alert)We’ll create an actionlet okAction = UIAlertAction.init(title: "Ok", style: .default) { _ in print("You tapped ok") //custom action here. }We’ll add the action to the alert and present italert.addAction(okAction) self.present(alert, animated: true, completion: nil)Now we’ll convert this ... Read More
To handle gestures in iOS application we’ll create an application with swift and see with help of an example. This can be done in two ways, with storyboard or programmatically.Method 1 − With storyboardFirst we’ll drag a swipe gesture recognizer from our object library and drop it in our View controller in which we want to add the swipe gesture.Then click on the gesture, press control and drag in your view controller class to create its connection.Make sure the sender of that action is UISwipeGestureRecognizer and the action looks something like this:@IBAction func swipeMade(_ sender: UISwipeGestureRecognizer) { }Now the swipe ... Read More
To make an image with round corners or to make any view or button or any UI element with round corners in swift, we need to access the corner radius property of its layer. Every UI element in iOS is based on a layer.First of all, let’s add an UIImageView Object in our storyboard. Or let’s create one programmatically.Below is a function that will programmatically create an image view and add an image to it.func addImage(imageName img: String) { let imageView = UIImageView() imageView.frame = CGRect(x: 10, y: 20, width: 200, height: 200) imageView.contentMode = . scaleAspectFill ... Read More
To create a segue from a UITableViewCell to another View controller, we’ll do it like any other ViewController to ViewController segue. We’ll do this with help of an example here.First Create a project, delete the View Controller from storyboard and add One Table View Controller and one View Controller in the storyboard.There will be one prototype cell in the Table View Controller by default. Click on it, go to its attribute inspector and give it “cell” as Identifier.Now from the prototype cell, press control and drag to the Second View Controller and select show from there.The storyboard should look like ... Read More
To extract last 4 characters from a string in swift we can use the internal functions of String class in swift.With new release every time methods have been modified, deprecated, added and improved in swift. Swift provides different methods to achieve the same. Let’s see these ways of doing it with a few examples.Method 1 − SubstringsIn swift three we were allowed to use a method called substring in which we could pass the string, it’s last index and the offset from which we wanted to trim the string.Let’s see an example of the same:var Str1 = "12312$$33@" print(Str1.substring(from:Str1.index(Str1.endIndex, offsetBy: ... Read More
To send an email from our iPhone device using our application we need to import the MessageUI framework of iOS SDK. After importing the framework in your application, drag and drop a button on the view controller. Add empty action for that button.Now add the following code in your view controller.funccomposeEmail(to email: String, subject: String, Body: String) { if( MFMailComposeViewController.canSendMail()) { letmailComposer = MFMailComposeViewController() mailComposer.mailComposeDelegate = self mailComposer.setToRecipients([email]) mailComposer.setSubject(subject) mailComposer.setMessageBody(Body, isHTML: true) letpathPDF = "\(NSTemporaryDirectory())result.pdf" if let fileData ... Read More
To access REST APIs in swift we need to go through a series of steps using the native way of networking in swift, that is using URL sessions and Data Tasks.Rest stands for Representational State Transfer, which defines some set of constraints that are to be used by web services. In swift, we can access web services in the following way.First of all, we need to create a session object, which default configuration.let configuration = URLSessionConfiguration.default let session = URLSession(configuration: configuration)Then we need to create an URL Request of The type we need, it can get, post, delete or put. ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP