-
Notifications
You must be signed in to change notification settings - Fork 10.4k
/
Copy pathAppKit_FoundationExtensions.swift
82 lines (70 loc) · 3.05 KB
/
AppKit_FoundationExtensions.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//===----------------------------------------------------------------------===//
//
// 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 AppKit
// NSCollectionView extensions
public extension IndexPath {
/// Initialize for use with `NSCollectionView`.
public init(item: Int, section: Int) {
self.init(indexes: [section, item])
}
/// The item of this index path, when used with `NSCollectionView`.
///
/// - precondition: The index path must have exactly two elements.
public var item : Int {
get {
precondition(count == 2, "Invalid index path for use with NSCollectionView. 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 NSCollectionView. This index path must contain exactly two indices specifying the section and item.")
self[1] = newValue
}
}
/// The section of this index path, when used with `NSCollectionView`.
///
/// - precondition: The index path must have exactly two elements.
public var section : Int {
get {
precondition(count == 2, "Invalid index path for use with NSCollectionView. This index path must contain exactly two indices specifying the section and item.")
return self[0]
}
set {
precondition(count == 2, "Invalid index path for use with NSCollectionView. This index path must contain exactly two indices specifying the section and item.")
self[0] = newValue
}
}
}
public extension URLResourceValues {
/// Returns all thumbnails as a single NSImage.
@available(OSX 10.10, *)
public var thumbnail : NSImage? {
return allValues[URLResourceKey.thumbnailKey] as? NSImage
}
/// The color of the assigned label.
public var labelColor: NSColor? {
return allValues[URLResourceKey.labelColorKey] as? NSColor
}
/// The icon normally displayed for the resource
public var effectiveIcon: AnyObject? {
return allValues[URLResourceKey.effectiveIconKey] as? NSImage
}
/// The custom icon assigned to the resource, if any (Currently not implemented)
public var customIcon: NSImage? {
return allValues[URLResourceKey.customIconKey] as? NSImage
}
/// Returns a dictionary of NSImage objects keyed by size.
@available(OSX 10.10, *)
public var thumbnailDictionary : [URLThumbnailDictionaryItem : NSImage]? {
return allValues[URLResourceKey.thumbnailDictionaryKey] as? [URLThumbnailDictionaryItem : NSImage]
}
}