2016年2月25日 星期四

for loop print json array


var dicArray = [
    ["quote": "Some text here1", "author": "guy1"],
    ["quote": "Some text here2", "author": "guy2"]
]

for element in dicArray {
    print(element)
    for(key,val) in element{
        print("key: \(key) /  val: \(val)")
    }
}


leancloud query, call back , get value


        let query: AVQuery = AVQuery(className: "story")
        query.whereKey("objectId", equalTo: "56c6f8362e958a0059fcd854")
        query.includeKey("question")
        
        
        query.findObjectsInBackgroundWithBlock({(objects: [AnyObject]?, error: NSError?) in
            
            let obj: AVObject = objects![0] as! AVObject
            let q: AVObject = obj["question"] as! AVObject
            
            self.studentLabel?.text = String(obj["name"])
            self.idLabel?.text = String(obj["object"])
            self.questionLabel?.text = String(q["name"])        
        })

2016年2月23日 星期二

EXC_BAD_INSTRUCTION (code=EXC_1386_INVOP, subcode=0x0)



when assigning a null val
or dividing a 0

@IBOutlet, Interface Builder scans

prefixing these variables with the @IBOutlet keyword. Interface Builder scans your code looking for any properties in your view controller prefixed with this keyword.



! , exclamation mark , implicitly unwrapped

exclamation mark (!). This indicates the variables are optional values, but they are implicitly unwrapped

Auto Layout

third button in the lower right of the Interface Builder (which looks like a Tie Fighter) and select All Views\Add Missing Constraints.


swift function declare












Functions with Parameters




Functions Without Return Values


Functions with Optional Return Types


Variadic Parameters
 to define function with multiple number of arguments


Pass by Reference