Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Khoa Nguyen KhoaVanNguyen

🏠
Working from home
  • Ho Chi Minh, VietNam
View GitHub Profile
View GroceriesTVC.swift
//
// Groceries.swift
// CoreDataChecklist
//
// Created by Khoa on 9/16/16.
// Copyright © 2016 Khoa. All rights reserved.
//
import UIKit
View AddTextFieldToAlertView1.swift
// create alert and a textfiled
let alert = UIAlertController(title: "Add", message: "Add new item", preferredStyle: .alert)
var groceryTF : UITextField!
@KhoaVanNguyen
KhoaVanNguyen / didSetwillSetVC.swift
Last active Dec 7, 2016
didSet and willSet in Swift
View didSetwillSetVC.swift
//
// didSetwillSetVC.swift
// didSetwill
//
// Created by Khoa on 12/7/16.
// Copyright © 2016 Khoa. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
View Objective-C Demo
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *CellIdentifier = @"CellIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(tableView == firstTableView)
{
//code for first table view
[cell.contentView addSubview: someView];
View Swift Demo
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
let cell:UITableViewCell = self.tableView.dequeueReusableCell(withIdentifier: cellReuseIdentifier) as UITableViewCell!
if(tableView == firstTableView) {
//code for first table view
}
if(tableview == secondTableView) {
//code for secondTableView
View Binary Search Demo
// Code from https://www.tutorialspoint.com/data_structures_algorithms/binary_search_algorithm.htm
Procedure binary_search
A ← sorted array
n ← size of array
x ← value to be searched
Set lowerBound = 1
Set upperBound = n
while x not found
View findIndex of
func findIndex(of number : Int , in array : [Int] ) -> Int?{
for ( index, value ) in array.enumerated(){
if value == number {
return index
}
}
return nil
}
// call it
View sayHelloTo
func sayHelloTo( parameter : String){
// use parameter in function
}
sayHelloTo(argument)
View Variadic Parameters
```swift
func printNames( names : String... ){
for name in names{
print(name)
}
}
printNames(names: "Swift","Go","Python","Java","C++")
```
View hide a view by touching outside of it in IOS
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?){
if touches.first?.view != subView{
// subView is your view
dismiss(animated: true, completion: nil)
}
}