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 tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { | |
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell",for: indexPath) as! CustomCell | |
let postitem = postAr[indexPath.row] | |
cell.lb_date.text = postitem.Msg_date | |
cell.userName.text = postitem.Msg_username | |
cell.userThumb.sd_setImage(with: URL(string: postitem.Msg_userThumb)) | |
//Here is how we deal with image |
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
DispatchQueue.global(qos: .background).async { | |
//running background | |
DispatchQueue.main.async { | |
// Go back to the main thread to update the UI | |
} | |
} |
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
//Tree | |
class Tree { | |
var root: Node? | |
func addValue(_ val: Int) { | |
let newNode = Node(value: val) | |
if self.root == nil { | |
print("root value is \(val)") | |
self.root = newNode | |
}else{ | |
root?.addNode(newNode) |
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
//Tree | |
class Tree { | |
var root: Node? | |
public func addValue(_ val: Int) { | |
let newNode = Node(value: val) | |
if self.root == nil { | |
print("root value is \(val)") | |
self.root = newNode | |
}else{ | |
root?.addNode(newNode) |
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
//把每個要比較的字sort後比較, 如果相同就放在一起 直到巡覽完全部再存到outPutAr 最後再一起輸出 | |
func groupAnagrams(_ strs: [String]) -> [[String]] { | |
var outPutAr = [[String]]() | |
var compareAr = Set(strs) | |
while compareAr.count > 0 { | |
let SameAr = returnSameAr(Array(compareAr)) | |
outPutAr.append(SameAr) //將處理完後的陣列存入 outPutAr | |
compareAr.subtract(SameAr) //移除已經加過的陣列元素 | |
} |
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
import UIKit | |
//把每個要比較的字sort後比較, 如果相同就放在一起 直到巡覽完全部再存到outPutAr 最後再一起輸出 | |
func groupAnagrams(_ strs: [String]) -> [[String]] { | |
var outPutAr = [[String]]() | |
var compareAr = Set(strs) | |
while compareAr.count > 0 { | |
let SameAr = returnSameAr(Array(compareAr)) | |
outPutAr.append(SameAr) //將處理完後的陣列存入 outPutAr |
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
var returnList = [Int]() | |
public func separateArray(_ ar:[Any]) { | |
for li in ar { | |
if li is Int { | |
returnList.append(li as! Int) | |
}else{ | |
for element in li as! Array<Any> { | |
if element is Int { | |
returnList.append(element as! Int) | |
}else{ |
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
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 | |
} |
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 |
OlderNewer