• Skip to main content
  • Skip to primary sidebar

Ravi Shankar

Tweaking Apps

  • About
  • Portfolio
  • Privacy Policy

Archives for July 2014

How to add Google as default search in Internet Explorer

July 31, 2014 By Ravi Shankar Leave a Comment

Internet Explorer is in-built with Bing as the default search engine. But it also provides users with the option to change the default search provider. Listed below are the steps for changing the default search engine in Internet Explorer 11 and 8

Make Google as default search engine in Internet Explorer 11

Launch Internet Explorer 11, navigate to address bar and click Search icon.

Search option in Address bar

Then click the Add Search Provider option in Search bar.

Add Search providers in Internet Explorer

Then select Google Search under Add-ons section

Select Google Search under Add-ons

In the Internet Explorer Gallery screen, click Add to Internet Explorer button.

Add Google Search to Internet Explorer

This should display the following Add Search Provider screen. Now mark the checkbox with caption as Make this my default search provider option. Then click Add button to confirm and save the changes.

make default search engine in Internet Explorer

Modifying default search provider using Manage add-ons option

If you had already added the search provider then you can follow the below mentioned steps to make it default.

Click the Tools menu and select Manage add-ons from the dropdown menu.

Manage add-ons in Internet Options

In the Manage Add-ons screen, navigate to Search Providers under Add-on-Types. Then select Google and click Set as default button.

Make Google Search as default

 

Set Google as default service provider in Internet Explorer 8

To add Google as a default search provider then it involves the following two steps

  • Adding Google Search Providers as Add-ons to Internet Explorer 8 (if not already added)
  • Changing the Google as the default search provider

You can use the Find More Search Providers and add Google to the Internet Explorer 8. Find More Search Providers can be accessed through Menu option available on clicking the Search text box drop down.

Find More Providers

Clicking on Find More Providers will display the Add-ons Gallery: Search Providers webpage and from this you can select Google and click on Add to Internet Explorer button. This would display Add Search Provider dialog box and to make Google as default search tick the check box Make this my default search provider and click on the Add button.

Add search provider in Internet Explorer

Filed Under: Internet Explorer Tagged With: Internet Explorer 11, Internet Explorer 8, Make Default, Manage add-ons, Search Provider

BlogReader App in Swift

July 31, 2014 By Ravi Shankar 28 Comments

In this iOS development tutorial, we will see how to write a blog feed Reader app in Swift Programming Language. For this demo, let us take the blog feed (https://rshankar.com/feed) from Learning Swift and iOS Development blog. This is a WordPress blog and the number of posts in the feed is set to 10 (This is configurable using WordPress Settings). For parsing this feed we will be using NSXMLParser and the parsed data will be displayed in a TableView. Then when the users taps on any post, the post URL will be displayed in a UIWebView.

Download source code from GitHub

201407311416.jpg 201407311417.jpg

Click File menu, select New then Project from the sub menu.

201407311021.jpg

In the template screen, choose Single View Application and click Next.

201407311022.jpg

In the options screen, enter the Product name and select language as Swift. Then choose a folder and save this new Project.

201407311024.jpg

Add a new TableViewController

Navigate to Main.storyboard and delete the default ViewController. From the object library, drag and drop a TableViewController on to the Storyboard.

201407311034.jpg

Now embed this TableViewController in a NavigationController, by clicking Editor menu and selecting Navigation Controller under Embed In menu option.

201407311035.jpg

Select ViewController.swift file under Project Navigator and delete the file.

201407311037.jpg

Right click on the Project folder and select New File option.

201407311038.jpg

In the Choose a template screen, select Cocoa Touch under iOS and click Next button.

201407311039.jpg

In the Choose options for new file screen, enter the class name as “BRTableViewController”, select Subclass of UITableViewController and Language as Swift.

201407311040.jpg

Using NSXMLParser for parsing the blog feed

Navigate to BRTableViewController.swift class declaration, add NSXMLParserDelegate after UITableViewController.

class BRTableViewController: UITableViewController, NSXMLParserDelegate{

This is required as we need to use some of the functions defined in NSXMLParserDelegate for parsing the feed. Now declare a NSXMLParser variable called parser.

var parser: NSXMLParser = NSXMLParser()

Then update the viewDidLoad method with the following code.

  override func viewDidLoad() {

super.viewDidLoad()

let url:NSURL = NSURL(string: “https://rshankar.com/feed”)

parser = NSXMLParser(contentsOfURL: url)

parser.delegate = self

parser.parse()

}

In the above lines of code, we are defining url for holding the feed. Then reinitialising the parser object with url and also setting the parser delegate to self. The parse( ) method would start parsing the feed. Before we write further code let us understand the structure of the blog feed. If you open the feed address (https://rshankar.com/feed) in your browser, you should notice the following XML structure.
201407311107.jpg
Each item element in the above screenshot provides details about the blog post. And on expanding item element, you should notice the following structure.
201407311110.jpg For this demo, we will be using the title and link elements only. The title will be displayed in the TableView and link will be displayed in UIWebView. In order to hold these title and link, let us create a placeholder class with two properties.
Right click on the Project folder, select New File and choose Swift File under iOS. Click Next and save the file as BlogPost.swift to the Project folder.
201407311132.jpg  
Navigate to BlogPost.swift, declare the class name as BlogPost and add two properties for holding title and link.

class BlogPost {

  

  var postTitle: String = String()

var postLink: String = String()

}

201407311200.jpg  
And to hold all the blog posts let us define variable of type array. Navigate to BRTableViewController.swift and add the following code after the parser variable

  var blogPosts: [BlogPost] = []

Implement the delegate method of NSXMLParser

Add the following three methods to BRTableViewController.swift. You can use Xcode autocomplete feature for adding these methods.

  // MARK: – NSXMLParserDelegate methods

  

func parser(parser: NSXMLParser!, didStartElement elementName: String!, namespaceURI: String!, qualifiedName qName: String!, attributes attributeDict: [NSObject : AnyObject]!) {

  

}

  

func parser(parser: NSXMLParser!, foundCharacters string: String!) {

  

}

  

func parser(parser: NSXMLParser!, didEndElement elementName: String!, namespaceURI: String!, qualifiedName qName: String!) {

  

}

  

As already observed in structure of the blog feed, the blog post is specified under the element named item. So we need to do all initialisation of the variables when the parser starts with this element name. Let us add the following the variables to the class declaration.

  var postTitle: String = String()

var postLink: String = String()

var eName: String = String()

Then initialise these variables didStartElement function when elementName is “item”

  func parser(parser: NSXMLParser!, didStartElement elementName: String!, namespaceURI: String!, qualifiedName qName: String!, attributes attributeDict: [NSObject : AnyObject]!) {

eName = elementName

if elementName == “item” {

postTitle = String()

postLink = String()

}

}

Then update foundCharacters function with the following code.

  func parser(parser: NSXMLParser!, foundCharacters string: String!) {

let data = string.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet())

if (!data.isEmpty) {

if eName == “title” {

postTitle += data

} else if eName == “link” {

postLink += data

}

}

}

In the above lines of code, we are removing the white space and newline character set. Then assign the values to corresponding variables if the content is not empty. Make sure to the append the values as the foundCharacters function will be called number of times for the same element name.
Then finally we add the following lines of code to didEndElement function. An instance of BlogPost is created and set with title and link values. Then this object is added to the blogPosts array.

  func parser(parser: NSXMLParser!, didEndElement elementName: String!, namespaceURI: String!, qualifiedName qName: String!) {

if elementName == “item” {

let blogPost: BlogPost = BlogPost()

blogPost.postTitle = postTitle

blogPost.postLink = postLink

blogPosts.append(blogPost)

}

}

Displaying the content in TableViewController

Navigate to the Table View Data source section and remove the commented line in numberOfSectionsInTableView and set the return value as 1.

  override func numberOfSectionsInTableView(tableView: UITableView!) -> Int {

return 1

}

The number of rows iN the table view will be equivalent to the total count of objects in blogPosts array. Update numberOfRowsInSection to reflect the array count.

  override func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int {

return blogPosts.count

}

Now uncomment cellForRowIndexPath function and update the function with the following lines of code.

  override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {

let cell = tableView.dequeueReusableCellWithIdentifier(“Cell”, forIndexPath: indexPath) as UITableViewCell

  

let blogPost: BlogPost = blogPosts[indexPath.row]

cell.textLabel.text = blogPost.postTitle

return cell

}

In the above lines of code, we have changed the cell identifier to “cell”. Then retrieved the content for the cell using the row index path from the blogPosts array. Then assigned the value of post title to cell’s textLabel.

Now navigate to Main.storyboard, select tableview cell and set the Identifier to Cell using the Attributes inspector.

201407311223.jpg

Then navigate to TableViewController and set the Class as BRTableViewController using the Identity inspector.

201407311224.jpg

Now if you compile and run the project in iOS simulator, you should see the list of blog posts as shown in the below screenshot.

201407311252.jpg

Let us make some cosmetic changes to the look of the table view. Navigate to Main.storyboard and add the title to navigation bar as Blog Reader.

201407311254.jpg

Then add the following function to BRTableViewController.swift for adjusting the row height of the tableview cell.

  override func tableView(tableView: UITableView!, heightForRowAtIndexPath indexPath: NSIndexPath!) -> CGFloat {

return 50.0

}

Now if you try to run the app on the simulator it should look as shown below.

201407311256.jpg

Displaying the post content in UIWebView

Now when users taps on post title, the user must be taken to another screen displaying the content of the post. For this purpose we to add another ViewController and use UIWebView for displaying the post content. Click Main.storyboard and add ViewController from object library to Storyboard. Now hold control and connect the UITableViewCell from BRTableViewController to the new ViewController, set the segue as “Show”. Then Provide the name of the Storyboard segue as viewpost.

201407311302.jpg

Add a UIWebView control from object library to ViewController. Right click on the Project folder and select New File for adding ViewController class.

201407311307.jpg

Select template as Cocoa Touch class and click Next button. Provide a name to the Class as PostViewController with Subclass of UIViewController. Then click Next and save the file to the Project folder.

201407311308.jpg

Using the Identity inspector the set the class name for the ViewController in the storyboard as PostViewController.

201407311311.jpg

Let us also add a UIActivityIndicatorView that would be displayed till the blog post is getting loaded on the WebView.

201407311313.jpg

Open PostViewController.swift file and add IBOutlets for UIWebView and UIActivityIndicatorView controls.

  @IBOutlet var webView:UIWebView!

@IBOutlet var activityIndicator: UIActivityIndicatorView!

In the class declaration, next to UIViewController add UIWebViewDelegate. This is required as we will be implementing two of the UIWebViewDelegate functions.

class PostViewController: UIViewController, UIWebViewDelegate

Then add the following postLink property, the value for this property will be set when the user taps any post on table view.

  var postLink: String = String()

Now update viewDidLoad function with following lines of code

  override func viewDidLoad() {

super.viewDidLoad()

let url: NSURL = NSURL(string: postLink)

let request: NSURLRequest = NSURLRequest(URL: url)

webView.loadRequest(request)

webView.delegate = self

}

The above lines of code, calls loadRequest of UIWebView by passing a NSURLRequest object. Then sets the delegate for webView to self. Now implement the following UIWebView delegate functions for showing and hiding Activity Indicator View.

  func webViewDidStartLoad(webView: UIWebView!) {

activityIndicator.hidden = false

activityIndicator.startAnimating()

}

  

func webViewDidFinishLoad(webView: UIWebView!) {

activityIndicator.hidden = true

activityIndicator.stopAnimating()

}

Finally use the connection inspector in the Interface builder to connect the IBOutlet variables (webView and activityIndicator) to the respective controls on the ViewController.

201407311318.jpg

Navigate to BRTableViewController.swift and add the prepareForSegue function. Check if the identifier is “viewpost” and then retrieve the post details for the selected row using tableView.indexPathForSelectedRow(). Then assign the post web url to viewController’s postLink property.

  override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) {

if segue.identifier == “viewpost” {

let blogPost: BlogPost = blogPosts[tableView.indexPathForSelectedRow().row]

let viewController = segue.destinationViewController as PostViewController

viewController.postLink = blogPost.postLink

}

}

Now if you compile and run the project, you should be able to view the post details on tapping any of the post in the table view.

201407311416.jpg

Download source code from GitHub

Filed Under: ios, Programming Tagged With: Blog Reader, Feed Reader, Swift, Wordpress blog

What is Caret browsing in Internet Explorer

July 28, 2014 By Ravi Shankar 15 Comments

Caret Browsing is cool feature available in Internet Explorer from version 8 onwards.

Rather than using a mouse to select text and move around within a webpage, you can use standard navigation keys on your keyboard-Home, End, Page Up, Page Down, and the arrow keys. This feature is called Caret Browsing and is named after the caret-or cursor-that appears when you edit a document.

You can press F7 to turn On or Off Caret browsing.

Turn on Caret Browsing

If you want to enable Caret browsing for new tabs or new windows then Enable Caret Browsing for new windows and tabs check box needs to be selected in Internet Options -> Advanced Tab.

Caret Browsing Internet Option

Filed Under: Browsers, Internet, Internet Explorer Tagged With: Internet Explorer 8, Tips

UIGestureRecognizer in Swift

July 23, 2014 By Ravi Shankar 9 Comments

In this short tutorial, we will see the steps required for implementing UIGestureRecognizer in Swift programming language. Let us take the previous Stop Watch demo code and implement tap, double tap and swipe gestures. You can download source code for Stop Watch from here.

201407231513.jpg

The following features will be implemented using the UIGestureRecognizer.

  • Tap – Starts the timer.
  • Double Tap – Stops the timer
  • Swipe (from left to right) – Resets the timer.

Remove the buttons

Since we are replacing the buttons with gestures, these buttons can be removed from the View Controller. Navigate to Main.storyboard and select the Start and Stop buttons and delete them. Make sure the timer label is centre aligned both vertically and horizontally. Then click Reset to Suggested Constraints under Resolve Auto Layout Issues option.

201407231527.jpg

Write Gestures code

Click SWViewController.swift file in the Project navigator and navigate to viewDidLoad function. Then add the following code to viewDidLoad method

  override func viewDidLoad() {

super.viewDidLoad()

  

let aSelector : Selector = “start:”

let tapGesture = UITapGestureRecognizer(target: self, action: aSelector)

tapGesture.numberOfTapsRequired = 1

view.addGestureRecognizer(tapGesture)

  

}

First this creates a constant to hold the selector argument which will be used when creating UITapGestureRecognizer. We are reusing the function that was used for the Start button.

Then we specify the numberOfTapsRequried and add the gesture as part of the view. Now repeat this for the stop button as well but for double tap.

  let bSelector : Selector = “stop:”

let doubleTapGesture = UITapGestureRecognizer(target: self, action: bSelector)

doubleTapGesture.numberOfTapsRequired = 2

view.addGestureRecognizer(doubleTapGesture)

  

tapGesture.requireGestureRecognizerToFail(doubleTapGesture)

The only difference is the number of taps required is specified as 2 and we are specifying that the single tap function will be called only when gesture is not double tap. Now if you try to run this project in the simulator, you should be able start and stop the timer using tap and double tap gestures.

Adding Swipe Gesture

When the user does a swipe from left to right, the values in the timer label must be set to 00:00:00. We can do this by using the UISwipeGestureRecognizer. Let us first the add function that resets the timer label.

  @IBAction func reset(sender: AnyObject) {

displayTimeLabel.text = “00:00:00”

}

Then add the following code to viewDidLoad method

  let cSelector : Selector = “reset:”

let rightSwipe = UISwipeGestureRecognizer(target: self, action: cSelector)

rightSwipe.direction = UISwipeGestureRecognizerDirection.Right

view.addGestureRecognizer(rightSwipe)

When a swipe from left to right is done the reset function is called. The viewDidLoad function with all the Gesture Recognizer should look as shown below.

  override func viewDidLoad() {

super.viewDidLoad()

  

let aSelector : Selector = “start:”

let tapGesture = UITapGestureRecognizer(target: self, action: aSelector)

tapGesture.numberOfTapsRequired = 1

view.addGestureRecognizer(tapGesture)

  

let bSelector : Selector = “stop:”

let doubleTapGesture = UITapGestureRecognizer(target: self, action: bSelector)

doubleTapGesture.numberOfTapsRequired = 2

view.addGestureRecognizer(doubleTapGesture)

  

tapGesture.requireGestureRecognizerToFail(doubleTapGesture)

  

let cSelector : Selector = “reset:”

let rightSwipe = UISwipeGestureRecognizer(target: self, action: cSelector)

rightSwipe.direction = UISwipeGestureRecognizerDirection.Right

view.addGestureRecognizer(rightSwipe)

}

Try running the project in simulator and check out tap, double tap and swipe gestures.

201407231555.jpg

Source code

Filed Under: Develop, ios, Xcode Tagged With: Swift, UIGestureRecognizer, UISwipeGestureRecognizer, UITapGestureRecognizer, Xcode

Simple StopWatch app in Swift

July 22, 2014 By Ravi Shankar 53 Comments

In this tutorial, we will see the steps for creating simple StopWatch app in Swift Programming language as shown in the below screenshot.

SimpleStopWatch demo

Click File menu -> New -> select Project from menu list.

Single View Application Xcode

Choose the template as Single View Application and click Next button.

Xcode select language as Swift

Enter name of the Product, Language as Swift then click Next to specify a folder and save the project.

Project Navigator in Xcode

Navigate to Project Navigator and select Main.storyboard. Using the Attributes Inspector, change the background colour for the ViewController to Dark Gray Colour

Attributes Inspector for View Controller

Navigate to Object Library, drag and drop UILabel to View Controller. Then align the label horizontally centred to the View Controller. Using the Attributes Inspector enter the label text as 00:00:00, change the colour to White, make the text centre aligned and increase the the font size to 27.0

Attributes Inspector for UILabel

Now drag and drop two buttons for starting and stopping the timer. Change the button text to Start and Stop respectively and set the Text Color to white.

201407221034.jpg

Now select ViewController.swift in the Project Navigator and delete the file, select Move to Trash in the Confirmation box.

201407221037.jpg201407221054.jpg

Let us add a new UIViewController file, right click on the SimpleStopWatch folder and select New File from the menu list.

201407221039.jpg

Select the template for the new file as Cocoa Touch Class (under iOS), then click Next

201407221042.jpg

Enter the name of the class as SWViewController, Subclass as UIViewController and Language as Swift. Then click Next and choose the Project folder to save the file.

201407221044.jpg

Navigate to SWViewController.swift and add a IBOutlet for UILabel.

[code language=”swift”]@IBOutlet var displayTimeLabel: UILabel!
[/code]

Then add two IBActions method for the two buttons, Start and Stop.

[code language=”swift”]
@IBAction func start(sender: AnyObject) {
}

@IBAction func stop(sender: AnyObject) {
}
[/code]

 

Navigate to Main.storyboard, select View Controller and specify the class name as SWViewController using the Identify Inspector

Identity Inspector for Class name

Now you should be able to see the IBActions and IBOutlet defined in the class file using Connection Inspector

Connections Inspector in Xcode 6

Drag and connect the UILabel with the IBOutlets, similarly connect IBActions with the buttons and specify the event as Touch Up Inside.

201407221100.jpg

Select the ViewController under View Controller Scene, click the Resolve Auto Layout Issues option and select Reset to Suggested Constraints. This would ensure that the alignment of controls remains the same for different screen size.

201407221108.jpg

Now if you try to run this project on Simulator, the screen would be as shown below. Nothing should happen on clicking the two buttons as we are yet to add the functionality.

201407221111.jpg

Write Code logic for StopWatch

Navigate to SWviewController.swift file and new function name as updateTime. This function will be used for calculating the time in minutes, seconds and fraction of milliseconds.

Add a new class level variable to the class for storing the start time.

[code language=”swift”]var startTime = NSTimeInterval()[/code]

Then add the following code in updateTime method. This is used for calculating the StopWatch time and assigning the value to the UILabel.

[code language=”swift”]</pre>
func updateTime() {

var currentTime = NSDate.timeIntervalSinceReferenceDate()

//Find the difference between current time and start time.

var elapsedTime: NSTimeInterval = currentTime – startTime

//calculate the minutes in elapsed time.

let minutes = UInt8(elapsedTime / 60.0)

elapsedTime -= (NSTimeInterval(minutes) * 60)

//calculate the seconds in elapsed time.

let seconds = UInt8(elapsedTime)

elapsedTime -= NSTimeInterval(seconds)

//find out the fraction of milliseconds to be displayed.

let fraction = UInt8(elapsedTime * 100)

//add the leading zero for minutes, seconds and millseconds and store them as string constants

let strMinutes = String(format: "%02d", minutes)
let strSeconds = String(format: "%02d", seconds)
let strFraction = String(format: "%02d", fraction)

//concatenate minuets, seconds and milliseconds as assign it to the UILabel

displayTimeLabel.text = “\(strMinutes):\(strSeconds):\(strFraction)”

}[/code]

Add a new class level NSTimer variable as shown below.

[code language=”swift”]</pre>
var timer = NSTimer()[/code]

Navigate to Start IBAction function and add the following the code.

 

[code language=”swift”]@IBAction func start(sender: AnyObject) {
let aSelector : Selector = “updateTime”
timer = NSTimer.scheduledTimerWithTimeInterval(0.01, target: self, selector: aSelector, userInfo: nil, repeats: true)
startTime = NSDate.timeIntervalSinceReferenceDate()
}
[/code]

This would start a timer and it repeats at regular time interval of 0.01. Here we specify the “updateTime” function which gets called regularly after the specified interval. We also initialise the startTime variable to the current time. Now when the user taps on Stop button, timer is invalidated and set to nil.

[code language=”swift”]
@IBAction func stop(sender: AnyObject) {
timer.invalidate()
timer == nil
}
[/code]

If you try to run this app on the simulator, you should notice the start and stop functionality works and time is getting displayed in the Label. But the user can repeatedly tap the Start button. So when the clock is running if the user taps the Start button, clock restarts again. We can prevent this by adding the following check to start the timer only when the timer is not running.

[code language=”swift”]@IBAction func start(sender: AnyObject) {
if !timer.valid {
let aSelector : Selector = “updateTime”
timer = NSTimer.scheduledTimerWithTimeInterval(0.01, target: self, selector: aSelector, userInfo: nil, repeats: true)
startTime = NSDate.timeIntervalSinceReferenceDate()
}
}[/code]

Download the source code from here

Filed Under: Develop, Programming, Xcode Tagged With: StopWatch, Swift, Xcode

How to rename project in Xcode

July 21, 2014 By Ravi Shankar 3 Comments

Xcode provides users with the option to rename the project. You can do this in Xcode 6 and Xcode 5 by following the below mentioned steps.

201407210907.jpg

Navigate to Project Navigator, select the Project. After entering the new name for the Project, press Return on the Keyboard. In this example, I am changing the name of project from StopWatch to MyStopWatch.

Once you press enter on the keyboard, the following confirmation screen will be displayed. Make sure you are Ok with the displayed changes then click Rename option.

201407210908.jpg

Filed Under: Xcode Tagged With: Rename Project, Xcode

Disable conversion of two numbers with hyphen as date in Excel

July 14, 2014 By Ravi Shankar Leave a Comment

Microsoft Excel has a feature that automatically coverts two numbers separated by hyphen in to a date formatted value. For example if you type 6-7 in a cell, Excel would reformat this in to a date value as 7-Jun. But if you do not want to reformat then you can use any of the below mentioned solutions to disable this feature.

Solution 1: Prefixing the values with apostrophe

The simplest solution is to add apostrophe before 6-7. This would display the typed value without reformatting it.

Auto format values with hyphen to date

Solution 2: Change format to Text Format

Another alternate solution is to change the formatting of the cell to Text format. Select the cell (or columns), right click and pick Format Cells from the menu list.

Format Cells in Excel

In the Format Cells window, select Text Format under Number tab and click OK button to apply the changes.

Change format to Text in Excel

Also See: How to prefix cell entry with zero in Excel 2013

Filed Under: Excel, Excel 2007, Excel 2010, Excel 2013, MS Office, Office 2007, Office 2010, Office 2013 Tagged With: Apostrophe, disable date, Format Cells, hyphen

Insertion Sort

July 3, 2014 By Ravi Shankar 2 Comments

Insertion Sort algorithm does the following

  • Keeps the sorted numbers from left to right.
  • Compares the left with right and interchanges the number if left is greater than right.

Here is code snippet of Insertion Sort in Swift.

[code language=”swift”]var inputArr:[Int] = [Int]()

// generate random numbers
for rIndex in 0..&lt;10 {
inputArr.append(((Int(arc4random()) % 100)))
}

func insertionSort(var inputArray :[Int]) -&gt; [Int] {
var jIndex:Int,kIndex:Int

for kIndex in 1.. 0 &amp;&amp; inputArray[jIndex-1] &gt;= temp ) {
inputArray[jIndex] = inputArray[jIndex-1]
–jIndex
}
inputArray[jIndex] = temp
}

return inputArray
}

insertionSort(inputArr)[/code]

Filed Under: Mac, Programming, Xcode Tagged With: algorithm, insertion Sort, Swift, Xcode

  • Go to page 1
  • Go to page 2
  • Go to Next Page »

Primary Sidebar

Recent Posts

  • We have blocked all requests from this device – Firebase Phone Authentication
  • iPhone is not available error message in Xcode
  • Clear CocoaPods cache, re-download and reinstall all pods
  • PDFKit – View, Annotate PDF file in Swift
  • Tab Bar Controller with WebView

Archives

  • September 2020
  • April 2020
  • December 2019
  • November 2019
  • October 2019
  • February 2019
  • October 2017
  • June 2017
  • May 2017
  • March 2017
  • September 2016
  • March 2016
  • February 2016
  • January 2016
  • December 2015
  • November 2015
  • October 2015
  • September 2015
  • August 2015
  • July 2015
  • June 2015
  • May 2015
  • April 2015
  • March 2015
  • February 2015
  • January 2015
  • December 2014
  • November 2014
  • October 2014
  • September 2014
  • August 2014
  • July 2014
  • June 2014
  • April 2014
  • March 2014
  • February 2014
  • January 2014
  • December 2013
  • October 2013
  • August 2013
  • July 2013
  • June 2013
  • April 2013
  • March 2013
  • February 2013
  • January 2013
  • November 2012
  • August 2012
  • July 2012
  • June 2012
  • May 2012
  • March 2012
  • February 2012
  • January 2012
  • December 2011
  • October 2011
  • September 2011
  • August 2011
  • July 2011
  • June 2011
  • April 2011
  • March 2011
  • January 2011
  • September 2010
  • August 2010
  • July 2010
  • June 2010
  • July 2009
  • March 2008

Copyright 2020 © rshankar.com