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
class ViewController: UIViewController { | |
@IBOutlet weak var collectionView: UICollectionView! | |
// create a collection view data list | |
var cellDataList:[Any] = [1, 1, 1, 1, 1, 1, 1] | |
// custom ui layout for collection view | |
let columnLayout = ColumnFlowLayout( | |
cellsPerRow: 5, |
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
class ColumnFlowLayout: UICollectionViewFlowLayout { | |
let cellsPerRow: Int | |
init(cellsPerRow: Int, minimumInteritemSpacing: CGFloat = 0, minimumLineSpacing: CGFloat = 0, sectionInset: UIEdgeInsets = .zero) { | |
self.cellsPerRow = cellsPerRow | |
super.init() | |
self.minimumInteritemSpacing = minimumInteritemSpacing | |
self.minimumLineSpacing = minimumLineSpacing | |
self.sectionInset = sectionInset |
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
指數 | 收盤指數 | 日期 | 漲跌(+/-) | 漲跌百分比(%) | 漲跌點數 | ||
---|---|---|---|---|---|---|---|
0 | 發行量加權股價指數 | 11,997.14 | 20191231 | <p style ='color:green'>-</p> | -0.47 | 56.23 | |
1 | 發行量加權股價指數 | 12,053.37 | 20191230 | <p style ='color:green'>-</p> | -0.32 | 38.22 | |
2 | 發行量加權股價指數 | 12,091.59 | 20191227 | <p style ='color:red'>+</p> | 0.75 | 90.58 | |
3 | 發行量加權股價指數 | 12,001.01 | 20191226 | <p style ='color:green'>-</p> | -0.06 | 7.12 | |
4 | 發行量加權股價指數 | 12,008.13 | 20191225 | <p style ='color:red'>+</p> | 0.27 | 31.75 | |
5 | 發行量加權股價指數 | 11,976.38 | 20191224 | <p style ='color:green'>-</p> | -0.38 | 45.85 | |
6 | 發行量加權股價指數 | 12,022.23 | 20191223 | <p style ='color:red'>+</p> | 0.53 | 63.15 | |
7 | 發行量加權股價指數 | 11,959.08 | 20191220 | <p style ='color:green'>-</p> | -0.5 | 59.82 | |
8 | 發行量加權股價指數 | 12,018.90 | 20191219 | <p style ='color:green'>-</p> | -0.85 | 103.55 |
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
// https://www.twse.com.tw/exchangeReport/MI_INDEX?response=json&date=20191121&type=IND | |
"fields1": [ | |
"指數", | |
"收盤指數", | |
"漲跌(+/-)", | |
"漲跌點數", | |
"漲跌百分比(%)" | |
] |
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
// https://www.twse.com.tw/exchangeReport/MI_INDEX?date=20191101&response=json&type=ALL | |
{ | |
"fields9": [ | |
"證券代號", | |
"證券名稱", | |
"成交股數", | |
"成交筆數", | |
"成交金額", | |
"開盤價", |
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
// 建立模擬的 Server public/private keys | |
let keyPair = try! SwiftyRSA.generate2048RSAKeyPairAdv() | |
let privateKey = keyPair.privateKey | |
let publicKey = keyPair.publicKey | |
inputPubkey.text = try! publicKey.base64String() | |
inputPrivkey.text = try! privateKey.base64String() | |
// 這裡簡化流程,正常情況下要拿對方公鑰加密,傳輸出去對方才能用私鑰解開 |
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
inputkey.text = "keykeykeykeykeyk" | |
inputIv.text = "drowssapdrowssap" | |
orgiTextView.text = "helloworld" | |
if | |
// 先做 AES-128 encode | |
let aes = try? AES(key: inputkey.text!, iv: inputIv.text!) , | |
let encrypted = try? aes.encrypt(orgiTextView.text!.bytes) , | |
// 再把結果用 base64 成文字顯示出來 | |
let EncData = encrypted.toBase64() |
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
// 取得 Query 的 body string | |
let dateString = query(dict) //使用預設的 URLEncoding.default 產生Body Encode | |
print(dateString) | |
// 以 sha256 把 key 和 body 作成簽名 | |
let keybytes: Array<UInt8> = input0.text!.bytes | |
let signature = try! HMAC(key: keybytes, variant: .sha256).authenticate(dateString.bytes) | |
print("signature \(signature.toHexString())") | |
// 將簽名跟 key id 放在 Header,傳出去 |
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
{ | |
"traceEvents": [ | |
{ | |
"pid": 1, | |
"tid": 0, | |
"ph": "X", | |
"ts": 3767, | |
"dur": 60732, | |
"name": "Module Load", | |
"args": { |
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
{ | |
"traceEvents": [ | |
{ | |
"pid": 1, | |
"tid": 0, | |
"ph": "X", | |
"ts": 95582, | |
"dur": 595, | |
"name": "Source", | |
"args": { |