iOS 10 總結(jié)

iiOS10添加了新的權(quán)限控制范圍 如果你嘗試訪問這些隱私數(shù)據(jù)時(shí)得到如下錯(cuò)誤:

> 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

因?yàn)樗髨D訪問敏感數(shù)據(jù)時(shí)沒有在應(yīng)用程序的Info.plist

設(shè)置privacy key 新增的privacy setting如下:

privacy setting

2, OS_ACTIVITY_MODE

更新Xcode 8 如果控制臺(tái)出現(xiàn)enable_level: 0, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0enable_oversize: 可通過如下方法設(shè)置:

Edit Scheme-> Run -> Arguments,

在Environment Variables里邊添加

OS_ACTIVITY_MODE = Disable

3,iOS10 layoutIfNeed

iOS10 在一個(gè)控件上調(diào)用layoutIfNeed是只會(huì)單獨(dú)計(jì)算約束,它所約束的控件不會(huì)生效,想要達(dá)到之前的效果需要在父級(jí)控件上調(diào)用layoutIfNeed

4, NSDate

Swift3.0會(huì)將oc的NSDate轉(zhuǎn)為Data類型,有些操作NSDate的第三方庫(kù)會(huì)閃退

5, Notification

Swift3.0字符串類型的通知常量被定義為struct

static let MyGreatNotification = Notification.Name("MyGreatNotification")

// Use site (no change)

NotificationCenter.default().post(name: MyController.MyGreatNotification, object: self)'

6, Zip2Sequence(::) 被移除

在Swift3.0Zip2Sequence(_:_:)方法被替換為zip(_:_:)

7, Range<>.reversed 被移除

在Swift3.0Range<>.reversed方法被移除,被替換為[].indices.reversed().

var array = ["A","B","C","D"]

for i in array.indices.reversed() {

print("\(i)")

}

輸出:3 2 1 0

8, Range新增至四種類型

Range

CountableRange

ClosedRange

CountableClosedRange

不同的表達(dá)式會(huì)生成不同的Range

var countableRange = 0..<20 'CountableRange(0..<20)'

var countableClosedRange = 0...20 'CountableClosedRange(0...20)'

9, Swift3.0 Collection 新增 index(_:)系列方法

Index的successor(), predecessor(), advancedBy(_:), advancedBy(_:limit:), or distanceTo(_:)方法被移除,這些操作被移動(dòng)到Collection

myIndex.successor()? =>? myCollection.index(after: myIndex)

myIndex.predecessor()? =>? myCollection.index(before: myIndex)

myIndex.advance(by: …) => myCollection.index(myIndex, offsetBy: …)

10, iOS10 UIStatusBar過期

如果你需要操作UIStatusBar,在iOS10需要改為

- (UIStatusBarStyle)preferredStatusBarStyle {

return UIStatusBarStyleDefault;

}

11, iOS10 UICollectionView 性能優(yōu)化

在iOS10 UICollectionView 最大的改變是增加了Pre-Fetching(預(yù)加載),

如果你翻看UICollectionView的最新API你可以發(fā)現(xiàn)新增了如下屬性:

@property (nonatomic, weak, nullable) id prefetchDataSource

@property (nonatomic, getter=isPrefetchingEnabled) BOOL

在iOS10 Pre-Fetching 是默認(rèn)開啟的,如果出于某些原因你不想開啟Pre-Fetching,可以通過如下設(shè)置禁用:

collectionView.isPrefetchingEnabled = false

UICollectionViewDataSourcePrefetching協(xié)議定義如下:

@protocol UICollectionViewDataSourcePrefetching

@required

// indexPaths are ordered ascending by geometric distance from the collection view

- (void)collectionView:(UICollectionView *)collectionView prefetchItemsAtIndexPaths:(NSArray *)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 *)indexPaths? NS_AVAILABLE_IOS(10_0);

@end

12, iOS10 UITableView 性能優(yōu)化

和UICollectionView一樣UITableView也增加了Pre-Fetching技術(shù),UITableView新增了如下屬性:

@property (nonatomic, weak) id prefetchDataSource NS_AVAILABLE_IOS(10_0);

奇怪的是UITableView并沒有找到isPrefetchingEnabled屬性的定義

13,iOS10 UIScrollView 新增 refreshControl 屬性

UIScrollView新增了refreshControl屬性

@property (nonatomic, strong, nullable) UIRefreshControl *refreshControl NS_AVAILABLE_IOS(10_0) __TVOS_PROHIBITED;

這意味著UICollectionView和UITableView都支持refresh功能了。

我們也可以脫離UITableViewController使用UIRefreshControl了。

14, Swif3.0 新增作用域訪問級(jí)別 fileprivate

目前有如下訪問級(jí)別:

公開(public)

內(nèi)部(internal)

文件外私有(fileprivate)

私有(private)

15,Swift3.0 允許關(guān)鍵字作為參數(shù)標(biāo)簽

Swift3.0開始我們將能使用除inout var let關(guān)鍵字作為參數(shù)標(biāo)簽

// 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

如果你堅(jiān)持要使用inout var let關(guān)鍵字可以使用 `` 包裹參數(shù)標(biāo)簽

func addParameter(name: String, `inout`: Bool)

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容