This file contains 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
// | |
// AppDelegate.swift | |
// CryptoCurrencyPayment | |
// | |
// Created by Nick on 4/16/20. | |
// Copyright © 2020 Nick. All rights reserved. | |
// | |
import UIKit | |
import Firebase |
This file contains 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
func splitCapitalString(_ textString:String) -> [String] { | |
var newStringArray = [String]() | |
for char in textString { | |
if String(char) == String(char).uppercased() { | |
newStringArray.append(" ") | |
} | |
newStringArray.append(String(char)) | |
} |
This file contains 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
// func startLoad() { | |
// let url = URL(string: "https://lemulotdotorg.files.wordpress.com/2016/10/dsc00737.jpg")! | |
// //init data | |
// receivedData = Data() | |
// let task = session.dataTask(with: url) | |
// task.resume() | |
// | |
// } | |
func startLoad(){ |
This file contains 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
// | |
// HTTPNetworking.swift | |
// urlSessionDemo | |
// | |
// Created by Nick on 12/2/18. | |
// Copyright © 2018 NickOwn. All rights reserved. | |
// | |
import Foundation | |
import UIKit |
This file contains 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
//MARK: - URLSessionDataDelegate | |
extension ViewController: URLSessionDataDelegate { | |
func urlSession(_ session: URLSession, dataTask: URLSessionDataTask, didReceive response: URLResponse, completionHandler: @escaping (URLSession.ResponseDisposition) -> Void) { | |
guard let httpResponse = response as? HTTPURLResponse, (200...299).contains(httpResponse.statusCode) else { | |
completionHandler(.cancel) | |
return | |
} | |
This file contains 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
//Session with configuration | |
private lazy var session: URLSession = { | |
let config = URLSessionConfiguration.default | |
config.waitsForConnectivity = true | |
return URLSession(configuration: config, delegate: self, delegateQueue: nil) | |
}() |
This file contains 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
@IBAction func action_loadImage(_ sender: UIButton) { | |
//disable button in case user click twice | |
sender.isEnabled = false | |
//start loading image | |
startLoad() | |
} | |
func startLoad() { | |
let url = URL(string: "https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png")! | |
This file contains 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
override init(style: UITableViewCellStyle, reuseIdentifier: String?) { | |
super.init(style: style, reuseIdentifier: reuseIdentifier) | |
//add UIImageView | |
customImageView = UIImageView() | |
customImageView.translatesAutoresizingMaskIntoConstraints = false | |
customImageView.backgroundColor = UIColor.red | |
self.addSubview(customImageView) | |
This file contains 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
//setup centerY with cell | |
//let labelConstraintCenterY = NSLayoutConstraint(item: customLabel, attribute: .centerY, relatedBy: .equal, toItem: self, attribute: .centerY, multiplier: 1, constant: 0) | |
//setup uilabel's height is equal 21 | |
//let labelConstraintHeight = NSLayoutConstraint(item: customLabel, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .height, multiplier: 1.0, constant: 21) | |
//self.addConstraints([labelConstraintCenterY]) | |
//Update use layout Anchor | |
customLabel.centerYAnchor.constraint(equalTo: self.centerYAnchor).isActive = true | |
customLabel.heightAnchor.constraint(equalToConstant: 21).isActive = true |
This file contains 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 UIImageView { | |
func loadImageUsingCache(withUrl urlString : String) { | |
let url = URL(string: urlString) | |
self.image = nil | |
// check cached image | |
if let cachedImage = imageCache.object(forKey: urlString as NSString) as? UIImage { | |
self.image = cachedImage | |
return | |
} |
NewerOlder