數(shù)據(jù)庫用完要close
當(dāng)我們向下面這樣執(zhí)行完一次數(shù)據(jù)可查詢時咽安,要記得將數(shù)據(jù)庫關(guān)閉媒殉,否則驰贷,如果此時想往同一數(shù)據(jù)庫寫東西的話會因為數(shù)據(jù)正在鎖定收到這樣的提示database is locked
。
//獲取下載完成的文件信息
func isExistdWith(_ id: String) -> Bool{
guard db.open() else {
return false
}
do {
let resultSet = try db.executeQuery("select * from tableName where id = ?", values: [id])
if resultSet.next() {
let isCompleted = resultSet.bool(forColumn: self.isCompleted)
db.close()//return之前要close數(shù)據(jù)庫
return isCompleted
}
} catch {
}
db.close()//return之前要close數(shù)據(jù)庫
return false
}
UIDatePicker的時間格式
當(dāng)我們用UIDatePicker做選擇時間的控件時削锰,DatePicker會根據(jù)手機時間的設(shè)置自動選擇是12小時制還是24小時制玷或,如果我們需要強制控制DatePicker是顯示12小時制還是24小時制可以這么做:
datePicker.datePickerMode = .time
datePicker.locale = Locale.init(identifier: "en_GB")//for 24 Hrs
datePicker.locale = Locale.init(identifier: "en_US")//for 12 Hrs
iOS skill map
iOS技能圖譜
變量對外只讀儡首,對內(nèi)可讀寫
struct Person {
private(set) var name : String!
}
設(shè)置UITableViewCell分割線對齊
默認(rèn)的cell分割線都是偏向右邊多一些的,如果我們想讓分割線對齊的話偏友,正確的做法是:
tableView.separatorInset = UIEdgeInsets.init(top: 0, left: 40, bottom: 0, right: 40)
設(shè)置左右邊距都是40
但是使用這種方法會帶來一個問題就是默認(rèn)的textLabel會跟著右移蔬胯。為了保持label的居中我們可以再加一句:
tableView.separatorInset = UIEdgeInsets.init(top: 0, left: 40, bottom: 0, right: 40)
tableView.layoutMargins = UIEdgeInsets.init(top: 0, left: 40, bottom: 0, right: 40)
富文本顯示圖片元素
如果我們需要文字中插入圖片元素時,可以使用富文本處理:
let attch = NSTextAttachment()
attch.image = UIImage.(named:"logo")
attch.bounds = CGRect.init(x: 0, y: 0, width: 18, height: 18)
let imageAttribute = NSAttributedString(attachment: attch)
titleLabel.attributedText = attributed
添加spotlight搜索索引
首先導(dǎo)入CoreSpotlight
和MobileCoreServices
框架位他,然后加入以下代碼:
var searchableItems = [CSSearchableItem]()
//索引項
let attributeSet = CSSearchableItemAttributeSet(itemContentType: kUTTypeData as String)
//title
attributeSet.title = "Item Title"
//desription
attributeSet.contentDescription = "match.description"
//thumb
attributeSet.thumbnailData = try? Data.init(contentsOf: URL(string: url)!)
//keywords
attributeSet.keywords = ["Love", "Peace"]
let searchableItem = CSSearchableItem(uniqueIdentifier: "app_keywords", domainIdentifier: "com.company.app", attributeSet: attributeSet)
searchableItems.append(searchableItem)
//建立索引
CSSearchableIndex.default().indexSearchableItems(searchableItems) { (error) -> Void in
if error != nil {
print(error?.localizedDescription ?? "Error")
}
}
Hexo編譯問題
在執(zhí)行hexo g
編譯markdown文件時莫名報錯:
TypeError: Cannot set property 'lastIndex' of undefined
解決方案是在_config.yml中將auto_detect
設(shè)為false
Podfile用法
# 下面兩行是指明依賴庫的來源地址
source 'https://github.com/CocoaPods/Specs.git'
source 'https://github.com/Artsy/Specs.git'
# 說明平臺是ios氛濒,版本是8.0
platform :ios, '8.0'
# 忽略引入庫的所有警告(強迫癥者的福音安 )
inhibit_all_warnings!
# 生成的是framework而不是靜態(tài)庫
use_frameworks!
# 針對MyApp target引入AFNetworking
# 針對MyAppTests target引入OCMock,
target 'MyApp' do
pod 'AFNetworking', '~> 3.0'
target 'MyAppTests' do
inherit! :search_paths
pod 'OCMock', '~> 2.0.1'
end
pod 'JSONKit', :podspec => 'https://example.com/JSONKit.podspec'
# 引入內(nèi)部庫
pod 'ABTest', :git => 'https://bitbucket.org/sealcn/remoteabtest.git'
pod 'ABTest', :git => 'https://bitbucket.org/sealcn/remoteabtest.git', :tag=> '0.0.6'
pod 'ABTest', :git => 'https://bitbucket.org/sealcn/remoteabtest.git', :commit=> '082f8319af'
# 編譯配置泼橘,指定僅在Debug模式下啟用
pod 'Reveal-SDK', :configurations => ['Debug']
# 使用本地文件
pod 'AFNetworking', :path => '~/Documents/AFNetworking'
# 指定版本號0.1.3到0.2涝动,不包括0.2
pod 'CHIPageControl', '~> 0.1.3'
# 僅安裝QueryKit下的Attribute和QuerySet模塊
pod 'QueryKit', :subspecs => ['Attribute', 'QuerySet']
end
# 這個是cocoapods的一些配置,官網(wǎng)并沒有太詳細(xì)的說明,一般采取默認(rèn)就好了,也就是不寫.
post_install do |installer|
installer.pods_project.targets.each do |target|
puts target.name
end
end