iOS10添加了新的权限控制范围 若是你尝试访问这些隐私数据时获得以下错误:性能优化
> This app has crashed because it attempted to access privacy-sensitive > data without a usage description. The app's Info.plist must contain > an NSCameraUsageDescription key with a string value explaining to the > user how the app uses this data
由于它企图访问敏感数据时没有在应用程序的Info.plist
设置privacy key 新增的privacy setting以下:app
更新Xcode 8 若是控制台出现enable_level: 0, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0enable_oversize: 可经过以下方法设置:ide
Edit Scheme-> Run -> Arguments, 在Environment Variables里边添加 OS_ACTIVITY_MODE = Disable
iOS10 在一个控件上调用layoutIfNeed是只会单独计算约束,它所约束的控件不会生效,想要达到以前的效果须要在父级控件上调用layoutIfNeedpost
Swift3.0会将oc的NSDate转为Data类型,有些操做NSDate的第三方库会闪退性能
Swift3.0字符串类型的通知常量被定义为structfetch
static let MyGreatNotification = Notification.Name("MyGreatNotification") // Use site (no change) NotificationCenter.default().post(name: MyController.MyGreatNotification, object: self)'
在Swift3.0Zip2Sequence(_:_:)方法被替换为zip(_:_:)优化
在Swift3.0Range<>.reversed方法被移除,被替换为<Collection>[<Range>].indices.reversed().ui
var array = ["A","B","C","D"] for i in array.indices.reversed() { print("\(i)") } 输出:3 2 1 0
Range CountableRange ClosedRange CountableClosedRange
不一样的表达式会生成不一样的Rangethis
var countableRange = 0..<20 'CountableRange(0..<20)' var countableClosedRange = 0...20 'CountableClosedRange(0...20)'
Index的successor(), predecessor(), advancedBy(_:), advancedBy(_:limit:), or distanceTo(_:)方法被移除,这些操做被移动到Collectionatom
myIndex.successor() => myCollection.index(after: myIndex) myIndex.predecessor() => myCollection.index(before: myIndex) myIndex.advance(by: …) => myCollection.index(myIndex, offsetBy: …)
若是你须要操做UIStatusBar,在iOS10须要改成
- (UIStatusBarStyle)preferredStatusBarStyle { return UIStatusBarStyleDefault; }
在iOS10 UICollectionView 最大的改变是增长了Pre-Fetching(预加载),
若是你翻看UICollectionView的最新API你能够发现新增了以下属性:
@property (nonatomic, weak, nullable) id<UICollectionViewDataSourcePrefetching> prefetchDataSource @property (nonatomic, getter=isPrefetchingEnabled) BOOL
在iOS10 Pre-Fetching 是默认开启的,若是出于某些缘由你不想开启Pre-Fetching,能够经过以下设置禁用:
collectionView.isPrefetchingEnabled = false
UICollectionViewDataSourcePrefetching协议定义以下:
@protocol UICollectionViewDataSourcePrefetching <NSObject> @required // indexPaths are ordered ascending by geometric distance from the collection view - (void)collectionView:(UICollectionView *)collectionView prefetchItemsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths NS_AVAILABLE_IOS(10_0); @optional // indexPaths that previously were considered as candidates for pre-fetching, but were not actually used; may be a subset of the previous call to -collectionView:prefetchItemsAtIndexPaths: - (void)collectionView:(UICollectionView *)collectionView cancelPrefetchingForItemsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths NS_AVAILABLE_IOS(10_0); @end
和UICollectionView同样UITableView也增长了Pre-Fetching技术,UITableView新增了以下属性:
@property (nonatomic, weak) id<UITableViewDataSourcePrefetching> prefetchDataSource NS_AVAILABLE_IOS(10_0);
奇怪的是UITableView并无找到isPrefetchingEnabled属性的定义
UIScrollView新增了refreshControl属性
@property (nonatomic, strong, nullable) UIRefreshControl *refreshControl NS_AVAILABLE_IOS(10_0) __TVOS_PROHIBITED;
这意味着UICollectionView和UITableView都支持refresh功能了。
咱们也能够脱离UITableViewController使用UIRefreshControl了。
目前有以下访问级别:
Swift3.0开始咱们将能使用除inout var let关键字做为参数标签
// Swift 3 calling with argument label: calculateRevenue(for sales: numberOfCopies, in .dollars) // Swift 3 declaring with argument label: calculateRevenue(for sales: Int, in currency: Currency) func touchesMatching(phase: NSTouchPhase, in view: NSView?) -> Set<NSTouch>
若是你坚持要使用inout var let关键字可使用 `` 包裹参数标签
func addParameter(name: String, `inout`: Bool)