mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
The SDK directory is now confusing as the Windows target also has a SDK overlay. In order to make this more uniform, move the SDK directory to Darwin which covers the fact that this covers the XNU family of OSes. The Windows directory contains the SDK overlay for the Windows target.
96 lines
3.5 KiB
Swift
96 lines
3.5 KiB
Swift
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This source file is part of the Swift.org open source project
|
|
//
|
|
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
|
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
//
|
|
// See https://swift.org/LICENSE.txt for license information
|
|
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
import Foundation
|
|
@_exported import UIKit
|
|
|
|
%{
|
|
from gyb_foundation_support import ObjectiveCBridgeableImplementationForNSValue
|
|
}%
|
|
|
|
// UITableView extensions
|
|
public extension IndexPath {
|
|
|
|
/// Initialize for use with `UITableView` or `UICollectionView`.
|
|
public init(row: Int, section: Int) {
|
|
self.init(indexes: [section, row])
|
|
}
|
|
|
|
/// The section of this index path, when used with `UITableView`.
|
|
///
|
|
/// - precondition: The index path must have exactly two elements.
|
|
public var section: Int {
|
|
get {
|
|
precondition(count == 2, "Invalid index path for use with UITableView. This index path must contain exactly two indices specifying the section and row.")
|
|
return self[0]
|
|
}
|
|
set {
|
|
precondition(count == 2, "Invalid index path for use with UITableView. This index path must contain exactly two indices specifying the section and row.")
|
|
self[0] = newValue
|
|
}
|
|
}
|
|
|
|
/// The row of this index path, when used with `UITableView`.
|
|
///
|
|
/// - precondition: The index path must have exactly two elements.
|
|
public var row: Int {
|
|
get {
|
|
precondition(count == 2, "Invalid index path for use with UITableView. This index path must contain exactly two indices specifying the section and row.")
|
|
return self[1]
|
|
}
|
|
set {
|
|
precondition(count == 2, "Invalid index path for use with UITableView. This index path must contain exactly two indices specifying the section and row.")
|
|
self[1] = newValue
|
|
}
|
|
}
|
|
}
|
|
|
|
// UICollectionView extensions
|
|
public extension IndexPath {
|
|
|
|
/// Initialize for use with `UITableView` or `UICollectionView`.
|
|
public init(item: Int, section: Int) {
|
|
self.init(indexes: [section, item])
|
|
}
|
|
|
|
/// The item of this index path, when used with `UICollectionView`.
|
|
///
|
|
/// - precondition: The index path must have exactly two elements.
|
|
public var item: Int {
|
|
get {
|
|
precondition(count == 2, "Invalid index path for use with UICollectionView. This index path must contain exactly two indices specifying the section and item.")
|
|
return self[1]
|
|
}
|
|
set {
|
|
precondition(count == 2, "Invalid index path for use with UICollectionView. This index path must contain exactly two indices specifying the section and item.")
|
|
self[1] = newValue
|
|
}
|
|
}}
|
|
|
|
public extension URLResourceValues {
|
|
|
|
/// Returns a dictionary of UIImage objects keyed by size.
|
|
@available(iOS 8.0, *)
|
|
public var thumbnailDictionary : [URLThumbnailDictionaryItem : UIImage]? {
|
|
return allValues[URLResourceKey.thumbnailDictionaryKey] as? [URLThumbnailDictionaryItem : UIImage]
|
|
}
|
|
}
|
|
|
|
// Bridge UIKit structs to NSValue.
|
|
|
|
${ ObjectiveCBridgeableImplementationForNSValue("UIEdgeInsets") }
|
|
|
|
@available(iOS 11.0, tvOS 11.0, watchOS 4.0, *)
|
|
${ ObjectiveCBridgeableImplementationForNSValue("NSDirectionalEdgeInsets") }
|
|
|
|
${ ObjectiveCBridgeableImplementationForNSValue("UIOffset") }
|