记录本月开发遇到的知识点,小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帮咱们解决了这个问题,一块儿了解一下吧!