get main queue

dispatch_async(dispatch_get_main_queue()) {
self.tableView.reloadData()
}

call selectrow

let rowToSelect:NSIndexPath = NSIndexPath(forRow: 0, inSection: 0); //slecting 0th row with 0th section
self.tableView.selectRowAtIndexPath(rowToSelect, animated: true, scrollPosition: UITableViewScrollPosition.None);

convertStringToDictionary

func convertStringToDictionary(text: String) -> [String:AnyObject]? {
if let data = text.dataUsingEncoding(NSUTF8StringEncoding) {
do {
return try NSJSONSerialization.JSONObjectWithData(data, options: []) as? [String:AnyObject]
} catch let error as NSError {
print(error)
}
}
return nil
}

create a fixed-size array of objects

arrayInfor = [Bool](count:4,repeatedValue:false)

Force-deleting stubborn or problematic files in Mac OS X

sudo rm -R

get array key of Dictionary

Array(Dictionary.keys)

Check if Localizable.strings file is valid

plutil -lint Localizable.strings

add gesture to image of cell

let tapGesture = UITapGestureRecognizer(target: self, action: #selector(self.tapEdit(_:)))
tableView.addGestureRecognizer(tapGesture)
tapGesture.delegate = self

lib add image with title vs Effect easy for Button

JTImageButton
https://github.com/kubatruhlar/JTImageButton
secondButton = JTImageButton(frame: CGRect(x: UIScreen.mainScreen().bounds.width - 80, y: 10, width:60 , height: 60))
secondButton.createTitle("Add", withIcon: UIImage(named: "ic_button_add"), font: UIFont.systemFontOfSize(18), iconHeight: JTImageButtonIconHeightDefault, iconOffsetY: 1.0)
secondButton.titleColor = UIColor.whiteColor()
secondButton.padding = JTImageButtonPaddingSmall

get the count of a Swift enum?

enum Test {
case ONE
case TWO
case THREE
case FOUR

static var count: Int { return Test.FOUR.hashValue + 1}
}
count returns 4.

Pages

Subscribe to Trần Mạnh Hoàng RSS