Skip to content

Instantly share code, notes, and snippets.

View evgeniyd's full-sized avatar
🌚

Yevhen Dubinin evgeniyd

🌚
View GitHub Profile
@evgeniyd
evgeniyd / ContainerView.m
Created September 27, 2024 06:42
RecognizeGesturesBetweenScrollViewAndButton
/*
The layout (notice how button is 50% on top of the collection view
while still added to the ContainerView)
|----------------------------------------------------|
| ContainerView |
| ------------------------------------------------ |
| | CollectionView | |
| | ___________ | |
| | | | | |
@evgeniyd
evgeniyd / NoteViewController.swift
Last active January 18, 2017 06:57
Swift 3: @autoclosure syntax to call functions upon UIAlertViewController's callbacks
/// The Medium artcile, discussing the approach
/// https://medium.com/@euginedubinin/swift-useful-autoclosure-when-presenting-uialertviewcontroller-b592d1643a50#.kx0fuqm1x
final class NoteViewController: UIViewController {
// ... set up target-action for an Edit UIButton somewhere here ...
private dynamic func handleEditButton() {
presentEditConfirmationDialog(onEdit: self.editArticle(),
onCancel: () ) /* assuming you have nothing to do upon cancellation */
@evgeniyd
evgeniyd / GlobalOnceClass.swift
Last active December 11, 2017 03:18
Swift 3: dispatch_once workarounds overview
import Foundation
private let justAOneTimeThing: () = {
print("\(GlobalOnceClass.self): Do This once")
}()
public final class GlobalOnceClass {
public init() {
}
@evgeniyd
evgeniyd / CharacterSet+ContainsOptionalUnicodeScalar.swift
Last active November 29, 2016 09:56
contains(_:) variant to work with Optional<UnicodeScalar>
// Swift 3
extension CharacterSet {
/// Test for membership of a particular `UnicodeScalar?` in the `CharacterSet`.
/// - important: This `contains(_:)` oveload works with `Optional<UnicodeScalar>`
///
/// Consider the following example:
/// ````
/// let flowermoji = "💐"
/// let ucscalar = UnicodeScalar(flowermoji.utf16.last!)
@evgeniyd
evgeniyd / NSTimeZone+SBTExtensions.h
Created September 27, 2016 12:19
NSTimeZone extension to convert GMT offset strings to NSTimeZone objects. It handles uneven (half-an-hour) offsets, like "-4.5", "+3.5", etc.. NOTE: there are no test and testing for offsets like 45 minutes and similar.
#import <Foundation/Foundation.h>
@interface NSTimeZone (SBTExtensions)
/*!
@brief Convert seconds, represented as a string to the timezone. Returns nil when conversion failed.
The method covers both, integers and floating point numbers.
*/
+ (nullable instancetype)timeZoneForSecondsFromGMTString:(nonnull NSString *)secondsString;
@end
@evgeniyd
evgeniyd / BasicExamplesFBSDK.m
Last active December 21, 2015 13:44
Basic actions with FBSDK 4.x
//
// Login via FBSDK
//
- (void)connectFacebookAccountWithCompletionHandler:(void (^)(NSError *))completionHandler
{
NSArray *readPermissions = @[@"public_profile", @"user_friends", @"email", @"user_likes"];
if (![FBSDKAccessToken currentAccessToken]) {
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login logInWithReadPermissions:readPermissions
@evgeniyd
evgeniyd / ConditionalRunningCrashReports.sh
Last active September 27, 2015 11:52
Crashlytics (Fabric) scripts collection. ConditionalRunningCrashReports.sh: not running in DEBUG; MultipleEnvironmentsCrashReports.sh - set up for different organisations. Note: Fabric is set up via CocoaPods
#!/bin/sh
releaseConfig="Release"
debugConfiguration="Debug"
adhocConfiguration="AdHoc"
if [ "$adhocConfiguration" = "${CONFIGURATION}" ] || [ "$releaseConfig" = "${CONFIGURATION}" ]; then
echo "Running Crashlytics"
"${PODS_ROOT}/Fabric/Fabric.framework/run" <your_api_key> <your_build_secret>
else
@evgeniyd
evgeniyd / MYNSRegularExpressionInitExample.swift
Last active September 24, 2015 20:59
NSRegularExpression w/ Swift 2.0; Two cases: 1) w/ catch-all” block 2) w/ "forced-try"
var input: String
// CASE 1
func validateWithError(error: NSErrorPointer) -> Bool {
var regexpError: NSError?
let regexp: NSRegularExpression?
do {
regexp = try NSRegularExpression(pattern: "[a-zA-Z0-9_]{4,}", options:[])
} catch let error as NSError {
regexpError = error
@evgeniyd
evgeniyd / CheckAlertViewIsShown.swift
Created September 22, 2015 22:39
A small function to check UIAlertView is shown (based on SO answer: http://stackoverflow.com/a/15151877/1492173)
private func isAlertExist() -> Bool {
for window in UIApplication.sharedApplication().windows {
if let w = window as? UIWindow where w.subviews.count > 0 {
for subview in w.subviews {
if let s = subview as? UIAlertView {
return true
}
}
}
}
@evgeniyd
evgeniyd / MYAppDelegate.m
Created September 14, 2015 09:25
Correct sequence of loading UISplitViewController from the storyboard manually
#import "MYAppDelegate.h"
@interface MYAppDelegate () <UISplitViewControllerDelegate>
/...
@property (nonatomic, strong) UISplitViewController* splitViewController;
@end
@implementation MYAppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {