Wednesday, July 29, 2015

Storing date in database

If year < 1970
    type = varchar
else
    type = DATE/DATETIME

Persistent Annotations in MapKit with Core Data

Have yet to try this but good for future reference

http://juliusdanek.de/blog/coding/2015/07/14/persistent-pins-tutorial/

Design Interfaces (a good read)

https://medium.com/elepath-exports/spatial-interfaces-886bccc5d1e9

Monday, July 27, 2015

Removing text field border after applying it

I encountered this problem today

I wanted to show to the user that a particular text field could be edited. Hence, I added a borderStyle with


self.phoneCodeTextField.borderStyle = .Line

But the problem is, I cannot remove the borderStyle with 

self.phoneCodeTextField.borderStyle = .None

Solution:

Make the textfield border rounded rect first before removing the border
self.phoneCodeTextField.borderStyle = .RoundedRect
self.phoneCodeTextField.borderStyle = .None

Wednesday, July 22, 2015

bottom border for collection view

Picture a 3x3 grid, there is a high chance that the bottom row of the grid is 50% thinner than the other borders in the collectionview since there is only 1 border there(instead of 2)

            let border = CALayer()
            //width of border
            let width = CGFloat(1.0)
            //border color
            border.borderColor = UIColor(red: 216.0/255.0, green: 216.0/255.0, blue: 216.0/255.0, alpha: 1.0).CGColor

            border.frame = CGRect(x: 0, y: cell.frame.size.height - width, width:  cell.frame.size.width, height: cell.frame.size.height)


            border.borderWidth = width
            cell.layer.addSublayer(border)

            cell.layer.masksToBounds = true

Monday, July 20, 2015

Change the height of rounded rect UITextField

You might notice that Apple has decided that the height for ALL rounded corner(default) UITextField is 30.
So to change the height, fight change the type or the border(regardless of which, and define the height in your storyboard)

Then, in viewDidLoad {
    self.nameOfTextField.borderStyle = UITextBorderStyle.RoundedRect
}

Thursday, July 16, 2015

dismiss keyboard when touch on screen

override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
        view.endEditing(true)
        super.touchesBegan(touches, withEvent: event)

    }

deleteCookie in swift


var cookieJar:[NSHTTPCookie] = NSHTTPCookieStorage.sharedHTTPCookieStorage().cookies as! [NSHTTPCookie]
        
if cookieJar.isEmpty == false {
    println("\n\n\nnot null\n\n\n")
    for cookie in cookieJar {
        NSHTTPCookieStorage.sharedHTTPCookieStorage().deleteCookie(cookie as NSHTTPCookie)
    }
}

Wednesday, July 15, 2015

tokenmismatchexception for laravel 5

It's necessary to include

<input type="hidden" name="_token" value="{{ csrf_token() }}">
in your post form.

Checking for nil

This occurred to me for a week.
In Objective-C, to check for nil, we can just
if (varName) {
    //not nil
} else {
    //nil
}
and do note that one handy thing in objective-c is that when you declare a variable, it assigns 0.

But thanks to optionals in swift, variables are not supposed to be nil.
So I was checking if cookies are persisting. And found out that I always return true, even if the println(cookie) result is
[]


So in Swift, you have to either call isEmpty
if cookieArray?.isEmpty == false{
     //cookie stored
} else {
    //no cookie :(
}

Tuesday, July 14, 2015

Cookies stored in NSHTTPCookieStorage doesn't persist

You may notice that you manage to 

println(NSHTTPCookieStorage.sharedHTTPCookieStorage().cookies!)
when you trigger setCookie(NSHTTPCookie!)

However,
If you're doing testing on a simulator, you may notice that your cookies doesn't persist through session.

Reason is the cookies are cached and not saved out to a file immediately.

It would only occur when the app receives a SIGKILL signal, like when the debugger is stopped from within Xcode. In my experiments, unhandled exceptions, crashes, exit() and abort() don't cause NSHTPPCookieStorage to loose data.

So if you want to test if your cookie storage is working fine, QUIT the simulator instead of killing the app from Xcode

Credits to: http://stackoverflow.com/questions/5747012/nshttpcookies-refuse-to-be-deleted/15198874#15198874

Monday, July 13, 2015

How to have 2 different UIPickerView for 2 different UITextField in the same UIViewController

Initial attempt:
drag 2 UIPickerView and control drag them and apply constraints to fit them to the bottom

However~
this will make your storyboard hard to maintain and messy, especially if you have UI elements that needed to be changed in the future.

The better solution could be:
Create 2 UIPickerView programatically

var statesPickerView: UIPickerView!
var phoneNumberPickerView: UIPickerView!

and then your toolbar(for Done or maybe stepper for form input)

var keyboardToolbar: UIToolbar!
keyboardToolbar = UIToolbar()
        keyboardToolbar.sizeToFit()
        var flexSpace = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.FlexibleSpace, target: nil, action: nil)
        var doneButton: UIBarButtonItem = UIBarButtonItem(title: "Done", style: UIBarButtonItemStyle.Done, target: self, action: Selector("dismissPickerView"))

        var barButtonItemsArray = NSMutableArray()
        barButtonItemsArray.addObject(flexSpace)
        barButtonItemsArray.addObject(doneButton)
        keyboardToolbar.items = barButtonItemsArray as [AnyObject]
        keyboardToolbar.sizeToFit()

add the toolbars to the inputview(picker view)
        self.phoneCodeTextField.inputAccessoryView = keyboardToolbar
        self.statesTextField.inputAccessoryView = keyboardToolbar
        self.phoneNumberPickerView = UIPickerView()
        self.statesPickerView = UIPickerView()

don't forget the delegates
        self.phoneNumberPickerView.dataSource = self
        self.statesPickerView.dataSource = self
        self.phoneNumberPickerView.delegate = self
        self.statesPickerView.delegate = self

 assign the pickerview as the inputview for the UITextFields
        self.phoneCodeTextField.inputView = phoneNumberPickerView
        self.statesTextField.inputView = statesPickerView


Another thing to note, you don't have to set the position or CGRectMake for your pickerview, thanks to the inputView property(e.g. your keyboard is at the bottom anyways).
Awesome <3

Wednesday, July 8, 2015

Steps for a session connection

/* 1. Set the parameters */ /* 2. Build the URL */ /* 3. Configure the request */ /* 4. Make the request */ /* 5. Parse the data */ /* 6. Use the data! */ /* 7. Start the request */

Friday, July 3, 2015

Problem installing homebrew(SSL certification error)

To install homebrew
$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" If you receive SSL certificate error

curl: (60) SSL certificate problem: unable to get local issuer certificate More details here: http://curl.haxx.se/docs/sslcerts.html curl performs SSL certificate verification by default, using a "bundle" of Certificate Authority (CA) public keys (CA certs). If the default bundle file isn't adequate, you can specify an alternate file using the --cacert option. If this HTTPS server uses a certificate signed by a CA represented in the bundle, the certificate verification probably failed due to a problem with the certificate (it might be expired, or the name might not match the domain name in the URL). If you'd like to turn off curl's verification of the certificate, use the -k (or --insecure) option. As mentioned in the error, you can bypass curl's verification. Hence use

$ ruby -e "$(curl -k -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Status bar text

Sometimes your design requires you to use a black navigation controller header. Which will camouflage your status' bar text.

So to change the status' bar text color you are required to do two things:

1) Go to info.plist(note it's the one in the ROOT folder, NOT the one in Supporting Files)
Add a new property "View controller-based status bar appearance" with the value NO

2) go to AppDelegate.swift and add in the following line

UIApplication.sharedApplication().setStatusBarStyle(.LightContent, animated: true)

phpmyadmin Existing configuration file (./config.inc.php) is not readable

Encountered this problem in the morning.

At first glance it looks like a permission issue, but after checking the file I realized that the file is empty, and there is a config.sample.inc.php that has full content.

Removing config.inc.php and renamed config.sample.inc.php to config.inc.php fixes the problem

Credits to https://forums.freebsd.org/threads/solved-apache-php-phpmyadmin-not-working-problem.45920/