Set Polygon Object Properties Using Function in Fabric.js

Rahul Gurung
Updated on 02-Jan-2023 14:44:58

143 Views

We can create a Polygon object by creating an instance of fabric.Polygon. A polygon object can be characterized by any closed shape consisting of a set of connected straight line segments. Since it is one of the basic elements of FabricJS, we can also easily customize it by applying properties like angle, opacity etc. Syntax set(key: String, value: String | Boolean | Number | Object | Function) Parameters key − This parameter accepts an String which specifies the property we want to set. value − This parameter accepts the value to be set for the property. ... Read More

Identify if Object is Polygon Instance in Fabric.js

Rahul Gurung
Updated on 02-Jan-2023 14:40:27

163 Views

We can create a Polygon object by creating an instance of fabric.Polygon. A polygon object can be characterized by any closed shape consisting of a set of connected straight line segments. Since it is one of the basic elements of FabricJS, we can also easily customize it by applying properties like angle, opacity etc. In order to identify if the given object is of a Polygon instance, we use the isType method. This method checks if the object is of the specified type and returns a true or false value depending on that. Syntax isType(type: String): Boolean Parameters ... Read More

Swift Print vs Println vs NSLog

Nitin Aggarwal
Updated on 02-Jan-2023 14:30:46

2K+ Views

In this article, you will learn about logging methods in the Swift language. You will also learn what the differences between them are. Debugging is the most common practice while writing code for an iOS application. It enables you to debug logic, code, errors, etc. Swift provides in-built libraries to print logs on the console. We have some options to print logs on the console like print(), println(), and NSLog(). Let's try to understand each of them. print() In Swift, print() is a function that prints a message to standard output (e.g., the console). It takes one or more arguments, ... Read More

Fatal Error: Unexpectedly Found Nil While Unwrapping an Optional Value

Nitin Aggarwal
Updated on 02-Jan-2023 14:29:11

5K+ Views

This error is very frequent as you can see many times while writing code. Don't worry, you will understand this error in detail in this article. Before jumping to the cause of this error, let's understand what is optional in Swift. Optional Initially, when we receive a value from another source, such as the backend server, it might contain a valid value or nothing at all. In that case, you use optionals that represent a variable with two possible situations: either a value or no value at all. var possibleNumber = "450" var convertedNumber = Int(possibleNumber) In the above ... Read More

Loading and Downloading an Image from a URL in Swift

Nitin Aggarwal
Updated on 02-Jan-2023 14:25:57

8K+ Views

In this article, you will learn how you can download an image from a URL in the Swift language. In the iOS application, image downloading from the image URL is the most common task. Apple provides us with a native library to download any data from any URL. There are many third-party libraries available on GitHub to download the images. But in this tutorial, we are not going to use any third-party library. We will use the URLSession class provided by Apple itself. What is the URLSession Class? URLSession is a class in the Foundation framework that provides an API ... Read More

Find Index of a List Item in Swift

Nitin Aggarwal
Updated on 02-Jan-2023 13:40:14

16K+ Views

Swift gives you some methods to perform on the collection type to get the index of a particular object. To find the index of an item in an array in Swift, you can use the firstIndex(of:) method of the Array type. This method returns the index of the first element in the array that is equal to the given element or nil if no such element is found. How to print the Index of List items? Let's look at an example. Algorithm Step 1 − Define an input array. Step 2 − Call the firstIndex() method on the input array. ... Read More

Add Constraints Programmatically Using Swift

Nitin Aggarwal
Updated on 02-Jan-2023 12:57:00

13K+ Views

The goal of this article is to explain how you can add constraints programmatically in the Swift language. To programmatically add constraints in Swift, you can use the NSLayoutConstraint class to define the constraints you want to add. Concepts That Will Be Used To Add Constraints Are The Following The translatesAutoresizingMaskIntoConstraints is a property of UIView in the UIKit framework. It is a boolean value that determines whether the view's autoresizingMask properties are translated into Auto Layout constraints. When translatesAutoresizingMaskIntoConstraints is set to NO, the autoresizingMask is ignored and the view is resized accrding to any constraints that have been ... Read More

Generate Random Number in Apple's Swift Language

Nitin Aggarwal
Updated on 02-Jan-2023 12:51:25

500 Views

This article will explain to you how to generate random numbers in the Swift language. There are some common situations when you need to generate random values in your iOS apps such as Simulating dice rolls. Shuffling playing cards. Create a unique ID for a user. The random value from collection type. In Swift 4.2, there are new, simple and secure ways to generate random values. Before that, there was a random function written in the C language. Today, you'll learn about the random() function that takes a range of values and as an output, it returns a ... Read More

Get Reference to App Delegate in Swift

Nitin Aggarwal
Updated on 02-Jan-2023 12:39:40

3K+ Views

You should know what an AppDelegate is in Swift before jumping to how to get a reference to it. AppDelegate In an iOS application, the app delegate is the entry point for the application. Throughout the application, this object has been created once by iOS and is accessible in shared mode. It's responsible for handling key events and tasks related to your app's lifecycle, such as responding to system notifications and managing the app's window and view hierarchy. Where it is Defined? The app delegate class is typically defined in the AppDelegate.swift file of your Xcode project. It should conform ... Read More

Get the Nth Character of a String in Swift

Nitin Aggarwal
Updated on 02-Jan-2023 12:34:42

2K+ Views

In this article, you will learn how to obtain the Nth character of a string. You will use the index() method to get the Nth character of a string. This method will give you the position index of the given string. How to use the Index() Method? Let's look at an example of how to use the index() method Algorithm Step 1 − Prepare an input string. Step 2 − Call the index() method with the target offset. Step 3 − Use the position index as a subscript to the input string. Step 4 − Store the Nth character. Example ... Read More

Advertisements