This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | let arrayOfArrays = [ [1, 1], [2, 2], [3, 3] ] | |
| let arrMultiple2 = arrayOfArrays.map { array in | |
| return array.map { integer in | |
| return integer * 2 | |
| } | |
| } // [ [2, 2], [4, 4], [6, 6] ] | |
| var flattened1 = arrayOfArrays.flatMap{ array in | |
| return array.map { integer in | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | struct User{ | |
| let id: Int | |
| let name: String | |
| init?(dictionary: [String:Any]) { | |
| guard | |
| let id = dictionary["id"] as? Int, | |
| let name = dictionary["name"] as? String | |
| else { | |
| return nil | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | let strs: [String?] = ["a", nil, "b", nil, "c"] | |
| let result = strs.map { $0 } | |
| print(result) // a nil b nil c | |
| let strs: [String?] = ["a", nil, "b", nil, "c"] | |
| let result = strs.flatMap { $0 } | |
| print(result) // a b c | |
| let scores = ["1", "2", "three", "4"] | |
| let scoresInt = scores.map { Int($0) } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | import UIKit | |
| // Khai báo 1 protocol | |
| protocol SetupConfig {} | |
| extension SetupConfig { | |
| @discardableResult | |
| public func withConfig(config:(inout Self) -> Void) -> Self { | |
| var mSelf = self | |
| // Config đối tượng là 1 block mà ta truyền vào | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | // Khai báo 1 protocol | |
| protocol SetupConfig {} | |
| extension SetupConfig { | |
| @discardableResult | |
| public func withConfig(config:(inout Self) -> Void) -> Self { | |
| var mSelf = self | |
| // Config đối tượng là 1 block mà ta truyền vào | |
| config(&mSelf) | |
| return mSelf | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | private let customView: UIView = { | |
| let view = UIView() | |
| view.frame = CGRect(x: 0, y: 20, width: 150, height: 150) | |
| view.backgroundColor = .red | |
| return view | |
| }() | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | extension UIView { | |
| @IBInspectable var cornerRadius: CGFloat { | |
| get { | |
| return layer.cornerRadius | |
| } | |
| set { | |
| layer.cornerRadius = newValue | |
| } | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | struct Customer: Decodable { | |
| init(from decoder: Decoder) throws { | |
| let values = try decoder.container(keyedBy: CodingKeys.self) | |
| name = try values.decode(String.self, forKey: .name) | |
| CustomerId = try values.decode(Int.self, forKey: .CustomerId) | |
| buyCar = try values.decode([Car].self, forKey: .buyCar) | |
| } | |
| } | |
| struct Car: Decodable { | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | struct Customer: Decodable { | |
| var CustomerId: Int | |
| var name: String | |
| var buyCar: [Car] | |
| enum CodingKeys: String, CodingKey { | |
| case CustomerId = "id" | |
| case name | |
| case buyCar | |
| } | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | let jsonString = "{\"id\":27,\"name\":\"Phong\",\"buyCar\":[{\"name\":\"VinFast LUX A2.0\",\"id\":1},{\"name\":\"Toyota Camry\",\"id\":2}]}" | |
| let jsonData = jsonString.data(using: String.Encoding.utf8) | |
| let jsonDecoder = JSONDecoder() | |
| let customer = try? jsonDecoder.decode(Customer.self, from: jsonData!) | 
NewerOlder