Found 517 Articles for Swift

How to Print a String in Swift Program?

Ankita Saini
Updated on 29-Jul-2022 09:50:50

565 Views

This tutorial will discuss how to write a swift program toprint a string. A string is a collection of characters such as “TutorialsPoint”, “Hello Purnima! How are you?”, etc. Strings can also be represented by Unicode. We can easily create and modifies a strings because they are lightweight and readable, also we can do string interpolation. Strings can be used to insert variable, constants expressions, etc.SyntaxFollowing is the syntax for creating string type variableVar a : StringAlgorithm to print two stringsStep 1 − Define 2 VariablesStep 2 − Enter string into that variableStep 3 − Perform operations with that stringStep ... Read More

Swift Program to Find the Perimeter of a Circle

Ankita Saini
Updated on 28-Jul-2022 09:53:05

2K+ Views

This tutorial will discuss how to write a Swift program to find the perimeter of the circle.Perimeter of the circle is also known as the circumference of the circle. It is used to calculate the boundary of the circle. Suppose we want to fence our circular garden so with the help of perimeter we can calculate the total amount of fence required to cover the boundary of the garden. We can calculate the perimeter of the circle with the help of the radius or diameter, here, Radius − It is known as the distance from the center to a point ... Read More

Swift Program to Find Area of Square

Ankita Saini
Updated on 28-Jul-2022 09:18:24

1K+ Views

This tutorial will discuss how to write a swift program to find the area of square.A Square is a two-dimensional closed figure with four equal side and four equal angle. It can also have two diagonals of equal length. The area of the square is known as the space that is enclosed inside the boundaries of the square. Suppose we have a square study table now the area of the square helps us to find how much cloth we required to cover the top of the table. The area of the square is the product of its two side.FormulaFollowing is ... Read More

How to Ping External host from Swift in iOS?

Smita Kapse
Updated on 30-Jul-2019 22:30:26

850 Views

Sometime you may require to ping an external website and check whether it’s up and running before you do any processing or fire request on the same.Here we will be seeing how to check whether the external website is up and running.Let’s being by Creating new projectStep 1 − Open Xcode → New Project → Single View Application → Let’s name it “PingMe”Step 2 − Open ViewController.swift and add the function checkIsConnectedToNetwork() and add the following code.func checkIsConnectedToNetwork() {    let hostUrl: String = "https://google.com"    if let url = URL(string: hostUrl) {       var request = URLRequest(url: ... Read More

Working with Xcode Auto Layout in Swift and iOS

Nishtha Thakur
Updated on 30-Jul-2019 22:30:26

2K+ Views

Auto layout is constraint based layout system used for development of User Interfaces for iOS Devices. This layout based constraint system also known as Auto Layout is basically an adaptive UI which adapts to screens of different sizes and orientations.Auto layout is completely dependent on constraints where developer defines a relation between neighbouring or parent element to seize it position.Why Auto Layout?While designing an iOS application you need to make sure, the UI which you’re developing should be equally compatible with all screen sizes and orientation. Auto layout comes handy when you wish to do so.Consider below images. A centrally ... Read More

How to lock Screen Orientation programmatically in iOS?

Nishtha Thakur
Updated on 30-Jul-2019 22:30:25

2K+ Views

You might come across a scenario where you need to show the UI in a specific orientation may be Landscape or Portrait.We will be seeing how to lock orientation programmatically using Swift in iOS.Open Xcode → New Project → ViewController.swift write the below code.// Set the shouldAutorotate to False override open var shouldAutorotate: Bool {    return false } // Specify the orientation. override open var supportedInterfaceOrientations: UIInterfaceOrientationMask {    return .portrait }

How to check if Location Services are enabled in iOS App?

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

1K+ Views

Location services as the name suggests gather the user information via GPS, Wifi and cell towers. Every iOS device has on board GPS, WiFi, cell tower location data and Bluetooth to determine the location of the iPhone or iPad. The user can enable or disable location services from the Settings app by toggling the Location Services switch in General.You should check the return value of locationServiceEnabled() method before starting location updates to determine whether the user has location services enabled for the current device.To check if Location Services are enabled in iOS app checkout the codeOpen Xcode → New Project ... Read More

How to detect iOS device UDID, Name, Version, Model by programmatically?

Nishtha Thakur
Updated on 30-Jul-2019 22:30:25

2K+ Views

Device UDID stands for Unique device identifier. Every iOS Device has UDID which is a sequence of 40 letters and numbers that is guaranteed to be specific to your device.Device name is generally a name which will find in the device Setting→ General→ About.iOS Version is the version on which your current iPhone runs, latest iOS version in 12.2iOS Model describes whether the iOS device which user is using is an iPhone/iPad.Now will see how to detect UDID, Name, Version and Model programatically.Open Xcode → New Project and add the below code in ViewController’s viewDidLoad method.override func viewDidLoad() {   ... Read More

How to get device make and model on iOS?

Smita Kapse
Updated on 30-Jul-2019 22:30:25

2K+ Views

When we talk about the device make, we refer to the Phone manufacturer (e.g. Apple, Samsung, Nokia and so on) and device model is generally the specific product such as iPhone, iPad/TAB etc.Any mobile devices will be categorized using make and model only.Now let’s understand how do I get device make and model in iOS?There are two ways to get make and model the first way is to directly open your iOS device, navigate to setting, tap on general and in the about section you can find the details of your iOS deviceThe second way is getting make and model ... Read More

Aligning two buttons vertically in iOS

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

571 Views

Auto Layout is one the most important element when it comes to designing an iOS Application. UI development has become a lot more versatile and easier using Auto Layout.For Aligning two buttons vertically we will be using Auto Layout.So let’s get started!Step 1: Open Xcode → New Projecr → Single View Application → Let’s name it “AlignButtons”Step 2: Open Main.storyboard and add two buttons, name them button 1 and button 2.Step 3: Select both the buttons and align them vertically using the Add New Alignment Constraint menu.Step 4: Select both the buttons tap on Add new constraints and set it ... Read More

Advertisements