Skip to content

Commit

Permalink
FIx race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Jun 22, 2020
1 parent 43e95e7 commit 65d18da
Show file tree
Hide file tree
Showing 46 changed files with 184 additions and 2,855 deletions.
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.yml]
indent_style = space
indent_size = 2
54 changes: 41 additions & 13 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,39 @@ whitelist_rules:
- comma
- compiler_protocol_init
- conditional_returns_on_newline
- contains_over_filter_count
- contains_over_filter_is_empty
- contains_over_first_not_nil
- contains_over_range_nil_comparison
- control_statement
- custom_rules
- deployment_target
- discarded_notification_center_observer
- discouraged_direct_init
- discouraged_object_literal
- discouraged_optional_boolean
- discouraged_optional_collection
- duplicate_enum_cases
- duplicate_imports
- dynamic_inline
- empty_collection_literal
- empty_count
- empty_enum_arguments
- empty_parameters
- empty_parentheses_with_trailing_closure
- empty_string
- empty_xctest_method
- enum_case_associated_value_count
- explicit_init
- fallthrough
- fatal_error_message
- first_where
- flatmap_over_map_reduce
- for_where
# Enable these once in a while
# - force_cast
# - force_try
# - force_unwrapping
- generic_type_name
- identical_operands
- identifier_name
Expand All @@ -48,6 +60,7 @@ whitelist_rules:
- legacy_constant
- legacy_constructor
- legacy_hashing
- legacy_multiple
- legacy_nsgeometry_functions
- legacy_random
- literal_expression_end_indentation
Expand All @@ -59,23 +72,27 @@ whitelist_rules:
- multiline_literal_brackets
- multiline_parameters
- multiline_parameters_brackets
- multiple_closures_with_trailing_closure
- nimble_operator
- no_extension_access_modifier
- no_fallthrough_only
- no_space_in_method_call
- notification_center_detachment
- nsobject_prefer_isequal
- number_separator
- object_literal
- opening_brace
- operator_usage_whitespace
- operator_whitespace
- orphaned_doc_comment
- overridden_super_call
- pattern_matching_keywords
- prefer_self_type_over_type_of_self
- private_action
- private_outlet
- private_unit_test
- prohibited_nan_comparison
- prohibited_super_call
- protocol_property_accessors_order
- reduce_boolean
- reduce_into
- redundant_discardable_let
- redundant_nil_coalescing
- redundant_objc_attribute
Expand All @@ -85,6 +102,7 @@ whitelist_rules:
- redundant_type_annotation
- redundant_void_return
- required_enum_case
- return_value_from_void_function
- return_arrow_whitespace
- shorthand_operator
- sorted_first_last
Expand All @@ -101,11 +119,13 @@ whitelist_rules:
- trailing_newline
- trailing_semicolon
- trailing_whitespace
- type_name
- tuple_pattern
- unavailable_function
- unneeded_break_in_switch
- unneeded_parentheses_in_closure_argument
- unowned_variable_capture
- untyped_error_in_catch
- unused_capture_list
- unused_closure_parameter
- unused_control_flow_label
- unused_enumerated
Expand All @@ -117,22 +137,18 @@ whitelist_rules:
- vertical_whitespace_closing_braces
- vertical_whitespace_opening_braces
- void_return
- weak_computed_property
- weak_delegate
- xct_specific_matcher
- xctfail_message
- yoda_condition
analyzer_rules:
- unused_declaration
- unused_import
- unused_private_declaration
force_cast: warning
force_try: warning
force_unwrapping: warning
number_separator:
minimum_length: 5
object_literal:
image_literal: false # Because image literals are practically unusable
discouraged_object_literal:
color_literal: false
identifier_name:
max_length:
warning: 100
Expand All @@ -152,6 +168,18 @@ identifier_name:
- 'x2'
- 'y1'
- 'y2'
iOS_deployment_target: '12.2'
excluded:
- Pods
deployment_target:
iOS_deployment_target: '13.5'
custom_rules:
no_nsrect:
regex: '\bNSRect\b'
match_kinds: typeidentifier
message: 'Use CGRect instead of NSRect'
no_nssize:
regex: '\bNSSize\b'
match_kinds: typeidentifier
message: 'Use CGSize instead of NSSize'
no_nspoint:
regex: '\bNSPoint\b'
match_kinds: typeidentifier
message: 'Use CGPoint instead of NSPoint'
199 changes: 60 additions & 139 deletions Blear.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions Blear/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
import UIKit
import AppCenter
import AppCenterCrashes

@UIApplicationMain
final class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?

func applicationDidFinishLaunching(_ application: UIApplication) {
MSAppCenter.start(
"266f557d-902a-44d4-8d0e-65b3fd19ae16",
withServices: [
MSCrashes.self
]
)

window = UIWindow(frame: UIScreen.main.bounds)
window?.rootViewController = ViewController()
window?.makeKeyAndVisible()
Expand Down
1 change: 0 additions & 1 deletion Blear/Blear-Bridging-Header.h
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
#import "UIImageEffects.h"
#import "JGProgressHUD.h"
8 changes: 6 additions & 2 deletions Blear/Constants.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import Foundation

let IS_IPAD = UIDevice().userInterfaceIdiom == .pad
let IS_IPHONE = UIDevice().userInterfaceIdiom == .phone
let IS_IPAD = UIDevice.current.userInterfaceIdiom == .pad
let IS_IPHONE = UIDevice.current.userInterfaceIdiom == .phone
let SCREEN_WIDTH = UIScreen.main.bounds.size.width
let SCREEN_HEIGHT = UIScreen.main.bounds.size.height
let IS_LARGE_SCREEN = IS_IPHONE && max(SCREEN_WIDTH, SCREEN_HEIGHT) >= 736.0

enum Constants {
static let initialBlurAmount = 50.0
}
11 changes: 7 additions & 4 deletions Blear/Images.xcassets/PickButton.imageset/Contents.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,21 @@
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
"author" : "xcode",
"version" : 1
},
"properties" : {
"template-rendering-intent" : "template"
}
}
4 changes: 2 additions & 2 deletions Blear/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.3.0</string>
<string>$(MARKETING_VERSION)</string>
<key>CFBundleVersion</key>
<string>12</string>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.photography</string>
<key>LSRequiresIPhoneOS</key>
Expand Down
15 changes: 13 additions & 2 deletions Blear/util.swift → Blear/Utilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ func with<T>(_ item: T, update: (inout T) throws -> Void) rethrows -> T {
return this
}


func delay(seconds: TimeInterval, closure: @escaping () -> Void) {
DispatchQueue.main.asyncAfter(deadline: .now() + seconds, execute: closure)
}


// TODO: Move it to a SPM module
// TODO: Add this as note to module readme:
// > Your app’s Info.plist file must provide a value for the NSPhotoLibraryUsageDescription key that explains to the user why your app is requesting Photos access. Apps linked on or after iOS 10.0 will crash if this key is not present.
Expand Down Expand Up @@ -139,6 +141,7 @@ extension PHPhotoLibrary {
}
}


extension UIBarButtonItem {
/**
```
Expand All @@ -157,6 +160,7 @@ extension UIBarButtonItem {
}
}


extension Collection {
/**
Returns a infinite sequence with consecutively unique random elements from the collection.
Expand Down Expand Up @@ -192,6 +196,7 @@ extension Collection {
}
}


extension UserDefaults {
var isFirstLaunch: Bool {
let key = "__hasLaunched__"
Expand All @@ -205,6 +210,7 @@ extension UserDefaults {
}
}


extension UIImage {
/// Initialize with a URL.
/// `AppKit.NSImage` polyfill.
Expand All @@ -228,6 +234,7 @@ extension UIImage {
}
}


extension UIView {
/// The most efficient solution.
@objc
Expand All @@ -238,6 +245,7 @@ extension UIView {
}
}


extension UIEdgeInsets {
init(all: CGFloat) {
self.init(top: all, left: all, bottom: all, right: all)
Expand All @@ -250,10 +258,12 @@ extension UIEdgeInsets {
func inset(rect: CGRect) -> CGRect { rect.inset(by: self) }
}


extension UIViewController {
var window: UIWindow { UIApplication.shared.windows.first! }
}


extension UIScrollView {
@objc
override func toImage() -> UIImage {
Expand All @@ -264,9 +274,10 @@ extension UIScrollView {
}
}


extension CGSize {
func aspectFit(to size: CGSize) -> CGSize {
func aspectFit(to size: Self) -> Self {
let ratio = max(size.width / width, size.height / height)
return CGSize(width: width * CGFloat(ratio), height: height * CGFloat(ratio))
return Self(width: width * CGFloat(ratio), height: height * CGFloat(ratio))
}
}
Loading

0 comments on commit 65d18da

Please sign in to comment.