Run a Timer in Background within Your iOS App

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

1K+ Views

If you wish to run a timer in background within your iOS Application, Apple provides beginBackgroundTaskWithExpirationHandler method, you can read more about the same developer.apple.com/documentation/uikit/uiapplication/1623031-beginbackgroundtaskwithexpiration.We will be using the same for writing our code for running the timer in background.So let’s begin.Step 1 − Open Xcode → Single View Application → Let’s name is BackgroundTimer.Step 2 − Open AppDelegate.swift and under method applicationDidEnterBackground write the below code.backgroundTaskIdentifier = UIApplication.shared.beginBackgroundTask(expirationHandler: {    UIApplication.shared.endBackgroundTask(self.backgroundTaskIdentifier!) }) _ = Timer.scheduledTimer(timeInterval: 1,  target: self,  selector: #selector(self.doSomething), userInfo: nil, repeats: true)Step 3 − Write new function doSomething()@objc func doSomething() {    print("I'm running") }Finally your code should look like belowfunc applicationDidEnterBackground(_ application: UIApplication) {    backgroundTaskIdentifier = UIApplication.shared.beginBackgroundTask(expirationHandler: { ... Read More

Create Empty Border with BorderFactory Class in Java

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

619 Views

To create empty border, use the createEmptyBorder() method. Let us first create a label component −JLabel label = new JLabel("Label with empty border!");Now, create empty border with BorderFactory class −label.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));The following is an example to create empty border −Examplepackage my; import javax.swing.BorderFactory; import java.awt.Font; import javax.swing.JFrame; import javax.swing.JLabel; public class SwingDemo {    public static void main(String[] args) throws Exception {       JFrame frame = new JFrame("Demo");       JLabel label;       label = new JLabel("Label with empty border!");       label.setFont(new Font("Verdana", Font.PLAIN, 16));       label.setVerticalAlignment(JLabel.BOTTOM);     ... Read More

Use Regex in MongoDB

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

319 Views

Following is the syntax to use $regex in MongoDB −db.yourCollectionName.find({yourFieldName: { $regex: yourValue}});Let us first create a collection with documents −> db.regularExpressionDemo.insertOne({"UserName":"John"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cdffc25bf3115999ed51210") } > db.regularExpressionDemo.insertOne({"UserName":"JOHN"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cdffc2ebf3115999ed51211") } > db.regularExpressionDemo.insertOne({"UserName":"john"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cdffc35bf3115999ed51212") } > db.regularExpressionDemo.insertOne({"UserName":"JoHn"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cdffc3ebf3115999ed51213") }Following is the query to display all documents from a collection with the help of find() method −> db.regularExpressionDemo.find();This will produce the following output −{ "_id" : ObjectId("5cdffc25bf3115999ed51210"), "UserName" : "John" } { ... Read More

HTML Button Type Attribute

George John
Updated on 30-Jul-2019 22:30:26

182 Views

The type attribute of the element is used to set type of the button. Following is the syntax −Above, we have shown the different types set for the button element i.e.: submit −button: A clickable buttonsubmit: Submit button (submits form-data)reset: It is a reset button to reset it to the initial value.Let us now see an example to implement the type attribute of the button element in HTML −Example Live Demo Investor Information Give the information about the investor interested in funding: ID: Investor: Funds: ... Read More

Get Properties of a Driver Using JDBC

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

1K+ Views

You can get the properties of a driver using the getPropertyInfo() method of the Driver interface.DriverPropertyInfo[] info = driver.getPropertyInfo(mysqlUrl, null);This method accepts a two parameters: A String variable representing the URL of the database, an object of the class Properties and, returns an array of the DriverPropertyInfo objects, where each object holds information about the possible properties of the current driver.From a DriverPropertyInfo object you can get the information such as name of the property, value of the property, description, choices and, if it is required or not, using its fields name, value, description, choices, required, respectively.DriverPropertyInfo[] info = driver.getPropertyInfo(mysqlUrl, ... Read More

C Program for Compound Interest

Arnab Chakraborty
Updated on 30-Jul-2019 22:30:26

1K+ Views

Here we will see how to get the compound interest by writing one C program. The logic is very easy. Here we need some parameters −P − Principle amountR − Rate of interestT − Time spanThe compound interest formula is like belowExample#include #include float compoundInterest(float P, float T, float R) {    return P*(pow(1+(R/100), T)); } int main() {    float p, t, r;    printf("Enter Princple amount, rate of interest, and time: ");    scanf("%f%f%f", &p, &r, &t);    printf("Interest value: %f", compoundInterest(p, t, r)); }OutputEnter Princple amount, rate of interest, and time: 5000 7.5 3 Interest value: 6211.485352

Change Display Mode with Java Swings

Krantik Chavan
Updated on 30-Jul-2019 22:30:26

1K+ Views

To change display mode with Java Swings, use the setDisplayMode() method. Here, we have set the Display mode as:new DisplayMode(800, 600, 32, 60));Now, when you will run the program, the frame would be visible in a different resolution than the actual set resolution of your system.The following is an example to change display mode with Java Swings:Exampleimport java.awt.DisplayMode; import java.awt.GraphicsDevice; import java.awt.GraphicsEnvironment; import javax.swing.JFrame; public class SwingDemo {    public static void main(String[] args) {       JFrame frame = new JFrame();       frame.setSize(800, 600);       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);       GraphicsDevice graphics = GraphicsEnvironment.getLocalGraphicsEnvironment()   ... Read More

Filter String List by Starting Value in Java

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

2K+ Views

Let’s first create a String list −List list = new ArrayList(); list.add("wxy"); list.add("zabc"); list.add("ddd2"); list.add("def"); list.add("ghi"); list.add("wer"); list.add("uij"); list.add("wqy");To filter String list by starting value, use filter() and startsWith() −list.stream().filter((b) -> b.startsWith("w"))The following is an example to filter string list by starting value −Exampleimport java.util.ArrayList; import java.util.List; public class Demo {    public static void main(final String[] args) {       List list = new ArrayList();       list.add("wxy");       list.add("zabc");       list.add("ddd2");       list.add("def");       list.add("ghi");       list.add("wer");       list.add("uij");       list.add("wqy");   ... Read More

Access SQLite Database Instance on iPhone

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

1K+ Views

Storing data is one of the most important thing when we design any application. There are numerous way to store data one such way is SQLite databse.There are multiple ways to access SQLite database on iPhone, We will be seeing the most easiest way to do so in Swift.SQLite is a relational database management system contained in C programming library embedded to an application.In this tutorial we will be creating one sample application which will have a text field to enter the name, we will store the name in our SQLite database and will print the same when user taps ... Read More

Delete First 10 Characters from JTextArea in Java

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

477 Views

Let’s say the following is our JTextArea with default text −JTextArea textArea = new JTextArea("The text added here is just for demo. "    + "This demonstrates the usage of JTextArea in Java. In this example we have"    + "deleted some text.");Now to remove the first 10 characters, use replaceRange() method and set null from one end to another i.e. deleting characters in a range. The replaceRaneg() method Replaces text from the indicated start to end position with the new text specified i.e.e here null will replace the first 10 characters −int start = 0; int end = 10; ... Read More

Advertisements