Found 516 Articles for Swift

Check if string contains another string in Swift

Samual Sam
Updated on 30-Jul-2019 22:30:24

362 Views

To check if a string contains another string in swift, we’ll need two different strings. One string that we have to check if it consists another string.Let us say the string we want to check is “point” and the whole string is “TutorialsPoint” and another string is “one two three”. Let’s check with both these string in the playground.We can do this in two ways as shown below. Let’s start by creating three different strings.var CompleteStr1 = "Tutorials point" var completeStr2 = "one two three" var stringToCheck = "point"Method OneIn this method we’ll use the .contains method of Strings to ... Read More

Push segue from UITableViewCell to ViewController in Swift

Samual Sam
Updated on 30-Jun-2020 05:50:40

707 Views

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

How to integrate PayU Money in iOS using swift?

karthikeya Boyini
Updated on 30-Jul-2019 22:30:24

315 Views

payU money is a payment gateway which is more popular in Indian online markets. To Integrate payU money we need to go through a few steps. Be careful with integrating payU and do not skip any of the steps of integration.Sign Up with payU money.Once you sign up, your key & salt, merchant ID will be generated which can be found in the dashboard after you login to your payU money account.After that in the terminal application, use the below code to clone payU money.Drag and drop the PlugNPlay folder to your project.$ git clone --recursive https://github.com/payu-intrepos/PayUMoney-IOS-SDK.gitNote − If you ... Read More

Capture picture from iOS camera using Swift

Samual Sam
Updated on 30-Jun-2020 05:35:25

3K+ Views

To capture pictures from a camera in swift we can use AVFoundation which is a framework in iOS SDK, but we should try to avoid using it until we need a lot of custom features in our camera application. In this example, we’ll only capture a picture from the camera and display it on the view. We’ll be using image picker in this example instead of AVFoundation.First, create a project and add an image view on its view Controller in the storyboard. Create the outlet in its class. Now inside the ViewController class conform it to −class ViewController: UIViewController, UIImagePickerControllerDelegate, ... Read More

How to use Swift to run in background to provide current location?

Samual Sam
Updated on 30-Jul-2019 22:30:24

725 Views

To get background location in swift we need to go through a few stepsGet the permissions from the user, in your info.plist file add Privacy- Location always andwhen in usage Description, Privacy – When in usage description and add their respective description.After that, you need to import the CoreLocation framework which will enable you to use all the location related libraries and methods. Then you need to get permission from the user to use the location. For that, we need to create a CLLocationManager Object and get authorization.var locationManager: CLLocationManager? override func viewDidLoad() { super.viewDidLoad() ... Read More

How to insert new cell into UITableView using Swift?

Rishi Rathor
Updated on 30-Jul-2019 22:30:24

1K+ Views

To insert a new cell into UITableView we'll first have to create a table view cell and then add it to the table view using Cell for row at method of Table view.We can create a cell using Storyboard or by creating a nib of class UITableViewCell.In the View controller drag and drop a table view and connect it's outlet to the ViewController class.Let's create a cell in the table view we just created and create it's class, call it CustomCell, and assign the class to cell.Give it an identifier "CustomCell"Add a label in the cell and change it to ... Read More

How to draw a route between two locations using MapKit in Swift?

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:24

928 Views

To draw a route between two Locations on map we need to have co-ordinates of both those locations.Once we have the co-ordinates of both locations we can use the below given function to show the line between two points on map. In this example I’ll be using two random location as two points.func getDirections(loc1: CLLocationCoordinate2D, loc2: CLLocationCoordinate2D) {    let source = MKMapItem(placemark: MKPlacemark(coordinate: loc1))    source.name = "Your Location"    let destination = MKMapItem(placemark: MKPlacemark(coordinate: loc2))    destination.name = "Destination"    MKMapItem.openMaps(with: [source, destination], launchOptions: [MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeDriving]) }We’ll call this function in ViewDidLoad for this tutorial to show the ... Read More

How to make iPhone vibrate using Swift?

Anvi Jain
Updated on 30-Jul-2019 22:30:24

2K+ Views

To make an iPhone vibrate using swift we’ll use two different methods. First create a new project and add Four different buttons to the main View controller.Now import the AudioToolbox framework in your view controller class.For the first button add an action and write the following code as shown below:@IBAction func actionButtonOne(_ sender: Any) {    AudioServicesPlayAlertSound(SystemSoundID(kSystemSoundID_Vibrate)) }This will generate a long vibrating feedback on your device. Now to create more vibration effects on devices with iOS 10 or more we’ll add methods for all four different buttons.@IBAction func actionButtonTwo(_ sender: Any) {    let generator = UIImpactFeedbackGenerator(style: .heavy)   ... Read More

How add 1 day to Date in swift?

Rishi Rathor
Updated on 30-Jul-2019 22:30:24

13K+ Views

To 1 day to a date in swift we need to create a date first. Once that date is created we have to add specific days to it. In this example we’ll see how we can achieve the same.Let’s create a date first, let it be today, let today = Date()Now to modify this date we’ll use the add function with negative value, let modifiedDate = Calendar.current.date(byAdding: .day, value: 1, to: today)!Now to see the difference between both the dates, let’s add print statement for both of these. Our complete code should now look like this.let today = Date() print(today) ... Read More

How to download a video using a URL and save it in an photo album using Swift?

Jennifer Nicholas
Updated on 29-Jun-2020 14:07:25

3K+ Views

To download a video from a URL in swift we need to perform a few steps while keeping a few things in mind.Points to be noted here are, We’ll be making use of internet to download video, hence we need to allow permissions for App transport security in our Info.plistWe’ll need to save the downloaded video to Photos app, hence photos permission is required.Video should always be downloaded in background as it may prevent us from using the app if downloaded on foreground.Now, we’ll use the below code to save a video from a random link in our Device. You’ll ... Read More

Advertisements