Wednesday, September 14, 2016

closure in swift

Closure is nuts!

Try run this code, and you will know what I am talking about


typealias IntegerFunction = Int -> ()

func  gamCounterSample() -> Int -> Void {
    func increment(i: Int){
        print("Integer passed in: \(i)")
    }
    return increment
}


func  gameCounter() -> IntegerFunction {
    var counter = 0
    
    func increment(i : Int){
        counter += i
        print("Counter value \(counter)")
    }
    
    return increment
}

let aCounter = gameCounter()
aCounter
aCounter(1)
aCounter(1)

Friday, September 9, 2016

tap and move collectionView

I was super pumped when found out about "installsStandardGestureForInteractiveMovement"

CollectionView is alway my go to when it comes to UI designs. Coz it makes everything more visualized, and easy to build the connection between the content and the users. 

To practice "installsStandardGestureForInteractiveMovement"
First, set up a basic collection.



import UIKit

private let reuseIdentifier = "Cell"

class PhotoCC: UICollectionViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        self.collectionView!.registerClass(UICollectionViewCell.self, forCellWithReuseIdentifier: reuseIdentifier)
    }


    override func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
        return 1
    }


    override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return 20
    }

    override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath)
        cell.backgroundColor = UIColor.grayColor()
        return cell
    }
}



Then set self.installsStandardGestureForInteractiveMovement = true
and 
    override func collectionView(collectionView: UICollectionView, moveItemAtIndexPath sourceIndexPath: NSIndexPath, toIndexPath destinationIndexPath: NSIndexPath) {
//code here

    }

The CollectionView will be ready to go.


The whole project is available at https://github.com/lingzt/CollectionViewTapMovePra

Thursday, September 8, 2016

partially reload tableview

Practice
1. reload section
2. reload row


I can totally see myself using these functions in the future.  Sometimes we just do not need to reload the whole tableview.

https://github.com/lingzt/TVRefreshSectionPra

Wednesday, September 7, 2016

copy and strong + swap function

basically

Copy: pass by value
Strong: pass by reference
more details: https://github.com/lingzt/CopyAndStrong



Swap function:

is to  swap values of two. 

The <T> in swap function means two value has to be of the same type. <T> does not mean any type specifically but only mean certain type in general. 





Thursday, September 1, 2016

AFNETWORKING CALL

Made a successful AFNETWORKING CALL today.
Pull a whole google task list to local via OBJC. Good progress!

https://github.com/lingzt/ToDoListPraOBJC