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)