Skip to content

Instantly share code, notes, and snippets.

View mediter's full-sized avatar
🎯
Focusing

Yuan, Jun mediter

🎯
Focusing
View GitHub Profile
@mediter
mediter / error.swift
Created May 20, 2018 14:47
[Error Handling] #swift #error
import Foundation
do {
//要做一些操作
let str = try NSString(contentsOfFile: filePath,encoding:   NSUTF8StringEncoding)//要尝试做的事情
} catch let err as NSError {//如果失败则进入catch代码块
@mediter
mediter / app_doc_path.swift
Created May 20, 2018 14:10
[App Document Directory] #swift #persistence
// MARK: - Data Persistence
func documentsDirectory() -> URL {
let paths = FileManager.default.urls(for: .documentDirectory,
in: .userDomainMask)
return paths[0]
}
func dataFilePath() -> URL {
return documentsDirectory().appendingPathComponent("Checklists.plist")
}
@mediter
mediter / tableview-background.swift
Created May 19, 2018 09:27
[Table View Background] #ios #swift #UITableView
tableView.backgroundColor = UIColor(red:1, green:1, blue:1, alpha:1.00)
let backgroundImageView = UIImageView(frame: view.bounds)
backgroundImageView.image = UIImage(named: "background")
backgroundImageView.alpha = 0.5
tableView.backgroundView = backgroundImageView
@mediter
mediter / statusbar.swift
Last active May 19, 2018 09:27
[Status Bar Height] #swift #ios #statusbar
// get the height of the status bar
let statusBarHeight = UIApplication.shared.statusBarFrame.height