記錄本月開發遇到的知識點,小tips,和bug總結。ios
新版iPad Pro、MacBook Air、Mac mini發佈,全線漲價,可是真香。。。 git
一、利用xcode快速遷移 升級到Xcode10以後,咱們打開項目會出現以下提示, github
點擊會有一個版本升級窗口,若是你的的項目包含一些第三方庫的話,第三方庫的選型也會出如今上面: swift
默認勾選第三方庫,可是咱們適配的時候不該該讓Xcode去自動檢索第三方庫代碼。只對咱們的app進行代碼遷移就夠了。 適配完後能夠在這裏查看咱們當前的swift版本: 數組
對於第三方庫,若是都適配了swift4.2,那麼更新到對應版本就好了。若是有沒適配的,能夠經過制定版本的方式解決衝突,在Podfile文件末尾添加以下代碼:xcode
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['SWIFT_VERSION'] = '4.0'
end
end
end
複製代碼
swift中提供的訪問權限關鍵詞由低到高有如下五種: private < fileprivate < internal < public < open 其中internal是Swift中的默認控制級,一下介紹了這幾種關鍵字的區別:緩存
對於一個嚴格的項目來講,精確的最小化訪問控制級別對於代碼的維護來講是很重要的。能用public的就別用open。ruby
當咱們執行某些命令行操做,收到以下提示時:bash
Linking /usr/local/Cellar/the_silver_searcher/2.1.0...
Error: Could not symlink etc/bash_completion.d/ag.bashcomp.sh
/usr/local/etc/bash_completion.d is not writable.
複製代碼
就代表咱們對須要修改的文件權限不夠,咱們能夠給文件加上修改的權限:app
sudo chown -R $(whoami) /usr/local/etc/bash_completion.d
複製代碼
其中-R
表示對目前目錄下的全部文件與子目錄進行相同的擁有者變動(即以遞迴的方式逐個變動)
public static let `default` = ImageCache(name: "default")
複製代碼
default是默認關鍵字,若是使用要加單斜號。
func tabBarController(UITabBarController, didSelect: UIViewController)
複製代碼
In iOS v3.0 and later, the tab bar controller calls this method regardless of whether the selected view controller changed. In addition, it is called only in response to user taps in the tab bar and is not called when your code changes the tab bar contents programmatically. In versions of iOS prior to version 3.0, this method is called only when the selected view controller actually changes. In other words, it is not called when the same view controller is selected. In addition, the method was called for both programmatic and user-initiated changes to the selected view controller.
tabbar的didSelect代理方法,只有在手動點擊的時候纔會觸發。經過代碼跳轉是不會觸發的。
// 當點擊tabBar的時候,自動執行該代理方法(不須要手動設置代理)
override func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem) {
for view in tabBar.subviews {
//控制view實現各類動畫效果
}
}
複製代碼
從xcode6.3開始,爲了能讓OC也能表示swift的?(optional)和!功能,增長了對對象的可選指定。指定屬性是否可選,能夠:
@property (nonatomic, copy, nonnull) NSString * tickets;
//或者
@property (nonatomic, copy) NSString * __nonnull tickets;
複製代碼
若是屬性多了,每個都這麼寫會很麻煩,蘋果增長了一對新的宏命令,就是NS_ASSUME_NONNULL_BEGIN
和NS_ASSUME_NONNULL_END
。放在裏面的對象就至關於都增長了nonnull
命令,nonull
爲默認值。
bug描述:
NSInternalInconsistencyException
UICollectionView received layout attributes for a cell with an index path that does not exist: <NSIndexPath: 0x280d2b200> {length = 2, path = 1 - 5}
複製代碼
緣由: layoutAttributesForElementsInRect
返回的UICollectionViewLayoutAttributes
數組有indexPath
沒有被 [NSIndexPath indexPathForRow:numberOfSection]
覆蓋。 當數據量增長時不會出問題,當數量減小時出現。有人反映這是iOS10的bug,但實際上,我拿iOS10模擬器跑並無問題,反而是在崩潰後臺看到是iOS12的用戶上報的。那究竟什麼緣由不詳,附stackoverflow(iOS 10 bug: UICollectionView received layout attributes for a cell with an index path that does not exist - Stack Overflow]地址。 解決方案: 當咱們自定義layout時,須要清除UICollectionViewLayoutAttributes的緩存
//方案一: 在自定義layout的類裏
override func prepare() {
super.prepare()
attributesArr.removeAll()
}
//方案二:在collectionview刷新出
collectionView.reloaData()
collectionView.collectionViewLayout.invalidateLayout()
複製代碼
一、設置git的user name和email
$ git config --global user.name "username"
$ git config --global user.email "username@gmail.com"
複製代碼
二、生成祕鑰
$ ssh-keygen -t rsa -C "username@gmail.com"
複製代碼
若是不須要設置密碼,連按三個回車。最後獲得了兩個文件:id_rsa
和id_rsa.pub
。 三、添加祕鑰到ssh-agent中
$ ssh-add ~/.ssh/id_rsa
複製代碼
四、登陸git倉庫(github或者bitbucket),添加ssh 將id_rsa.pub
文件的內容複製到對應的地方。
一、watch沒有UIKit,對於UI的操做只能經過storyboard
進行 二、watch只支持幀動畫,咱們只能經過png序列來實現動畫效果。WKInterfaceGroup
和 WKInterfaceImage
都可以實現幀動畫。 三、開發的watch應用內存被限定爲80M,太多幀的動畫會不支持 四、提交應用watch也須要配置市場截圖。 五、watch分爲兩個target。當新建一個Target爲WatchDemo,xcode會自動生成一個WatchDemo Extension。前者負責UI,後者負責邏輯。引用cocoapods能夠這麼寫:
target 'WatchDemo Extension' do
platform :watchos, '3.0'
use_frameworks!
pod 'Alamofire'
end
複製代碼
六、Always Embed Swift Standard Libraries 在Build Settings裏面,這兩個target,須要將WatchDemo Extension中設置爲Yes,另外一個設置爲No
Sizes 能夠在一個界面,顯示各個屏幕尺寸。這樣咱們就不用每一個模擬器跑一遍看效果了。方便調試。
iOS-DeviceSupport 當手機升級,而xcode未升級時,咱們會遇到Device Support的彈框,此時要麼升級xcode,要麼須要導入對應的Device Support文件。這個庫就是提供這種文件的。
InjectionIII 用於解決煩人的UI調試問題。當修改了一些UI屬性以後,在xcode中咱們只能運行程序才能看到效果,若是是處理大量的UI問題,這個過程是很煩人的。好在InjectionIII幫咱們解決了這個問題,一塊兒瞭解一下吧!