Showing and hiding rows in a iOS tableView

So I would like to use a tableView to show a list of controls

On one row I would like a date, and on the next row I’d like a CalendarPicker. I want the calendarPicker row to appear or disappear when I click on the date row. This looks like a way to handle it:

 var expandedRow = -1; //sentinal value
    var heights:[CGFloat] =  [44.0,44.0]
    let HiddenRowHeight: CGFloat = 0.0
    let ExpandedRowHeight: CGFloat = 88.0
    let DefaultHeight: CGFloat = 44.0
    func tableView(tableView: UITableView!, didSelectRowAtIndexPath indexPath: NSIndexPath!) {
        //assume row  0 shows the date
        //assume row 1 shows a Calendar picker
        var currentRow: Int = indexPath.row
        if(currentRow == 0) //assume row 0 is the row with a date
            //if the calendar is showing, hide it.
            //if it is hidden, show it
             if expandedRow == currentRow + 1
                //shrink it
                heights[currentRow + 1] = HiddenRowHeight
                expandedRow = -1
                //expand it
                heights[currentRow + 1] = ExpandedRowHeight
                 expandedRow = currentRow + 1
    func tableView(tableView: UITableView!, heightForRowAtIndexPath indexPath: NSIndexPath!) -> CGFloat {
        //get the height of the row from the array of heights
        var height = DefaultHeight
        var row = indexPath.row
        if heights.count > row
            height = heights[row]
        return height


I’ll refine this article after I implement the screen.

Overriding the default constructor parameters using Ninject

I use Ninject for my IoC Container in most of my projects, at this time.

When setting up my infrastructure layer, it is pretty common that I’ll need to send along some value that isn’t the default.

To send a non-default class, such as the case where I want to send a DbContext other than the default, I use this method:

//MyEntitiesClass is generated by the EDMX in my domain layer.
                .WithConstructorArgument("dbContext", kernel.Get());

//assume myConnString has been loaded from web.config just before this is called.
                .WithConstructorArgument("connString", myConnString);

That is pretty simple.

.Net Request size limits

There are 2 settings in the web.config for managing request size limits

This is how to allow 8 MB request length:
First the httpRuntime maxRequestLength is in KB so 8192KB = 8MB

    <customErrors mode="Off"/>
    <compilation debug="true"/>
    <httpRuntime targetFramework="4.5"
       maxRequestLength="8192"          />

Next, ‘requestLimits maxAllowedContentLength’ is in bytes so 8388608 bytes = 8MB

       <requestLimits maxAllowedContentLength="8388608" ></requestLimits>


Converting a date from JSON to NSDate using Swift

I had a lot of difficulty getting a date from a REST service and then using within my Swift code. Actually the only difficulty was converting the REST data into something that Swift was happy with.

Let’s assume that you have made your rest call and retrieved your data. In my case, dates could be null so I’m performing an ‘if let’ statement to make sure I get a valid value before trying to convert it. Then I call a function I named ‘getDate(…)’ to turn the string into a NSDate.

Here are the important bits of this process:

 if let dueDate = elem["DueDate"] as? NSString
                t.DueDate = getDate(dueDate)

And here is the getDate function:

    func getDate(dateString:NSString) -> NSDate{
        var dateFormatter = NSDateFormatter()

        if(dateString.length == 19)
            dateFormatter.dateFormat = "YYYY-MM-dd'T'HH:mm:ss" //This is the format returned by .Net website
        else if(dateString.length == 21)
            dateFormatter.dateFormat = "YYYY-MM-dd'T'HH:mm:ss.S" //This is the format returned by .Net website
        else if(dateString.length == 22)
            dateFormatter.dateFormat = "YYYY-MM-dd'T'HH:mm:ss.SS" //This is the format returned by .Net website
        else if(dateString.length == 23)
             dateFormatter.dateFormat = "YYYY-MM-dd'T'HH:mm:ss.SSS"

        var date = dateFormatter.dateFromString(dateString)
        return date!;

Common date functions in SQL

Useful for checking that the date range is less than the given end date.


Assuming you are given a date that can fall on any day within a month:

Get the first day of the month containing @startDate:

set @currentMonthStartDate = DATEADD(month, DATEDIFF(month, 0, @startDate), 0)

Get the last day of the month containing @startDate:

set @currentMonthEndDate = DATEADD(day,-1, DATEADD(month, DATEDIFF(month, 0, @startDate) + 1, 0) );

X-Frame-Options in MVC 5

I had created an application that was meant to be displayed in a frame loaded from another url. There were issues with the frame not loading properly and using developer tools the console displayed the error:

Refused to display '...' in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'

The fix to this was to add :

AntiForgeryConfig.SuppressXFrameOptionsHeader = true; 

to the Application_Start function in Global.asax. You must also add:

using System.Web.Helpers;

to get access to that.

ios 8 – closing the keyboard

Closing the keyboard:

import UIKit

class ViewController: UIViewController, UITextFieldDelegate {

    @IBOutlet var text: UITextField!
    @IBOutlet var label: UILabel!
    @IBAction func buttonPressed(sender: AnyObject) {
        label.text = text.text
    override func viewDidLoad() {
        // Do any additional setup after loading the view, typically from a nib.
        self.text.delegate = self

    override func didReceiveMemoryWarning() {
        // Dispose of any resources that can be recreated.

    override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
    func textFieldShouldReturn(textField: UITextField!) -> Bool {
        return true