Skip to content

Instantly share code, notes, and snippets.

Yevhen Dubinin evgeniyd

Block or report user

Report or block evgeniyd

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@evgeniyd
evgeniyd / NoteViewController.swift
Last active Jan 18, 2017
Swift 3: @autoclosure syntax to call functions upon UIAlertViewController's callbacks
View NoteViewController.swift
/// 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 Dec 11, 2017
Swift 3: dispatch_once workarounds overview
View GlobalOnceClass.swift
import Foundation
private let justAOneTimeThing: () = {
print("\(GlobalOnceClass.self): Do This once")
}()
public final class GlobalOnceClass {
public init() {
}
@evgeniyd
evgeniyd / CharacterSet+ContainsOptionalUnicodeScalar.swift
Last active Nov 29, 2016
contains(_:) variant to work with Optional<UnicodeScalar>
View CharacterSet+ContainsOptionalUnicodeScalar.swift
// 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 Sep 27, 2016
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.
View NSTimeZone+SBTExtensions.h
#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 Dec 21, 2015
Basic actions with FBSDK 4.x
View BasicExamplesFBSDK.m
//
// 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 Sep 27, 2015
Crashlytics (Fabric) scripts collection. ConditionalRunningCrashReports.sh: not running in DEBUG; MultipleEnvironmentsCrashReports.sh - set up for different organisations. Note: Fabric is set up via CocoaPods
View ConditionalRunningCrashReports.sh
#!/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 Sep 24, 2015
NSRegularExpression w/ Swift 2.0; Two cases: 1) w/ catch-all” block 2) w/ "forced-try"
View MYNSRegularExpressionInitExample.swift
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 Sep 22, 2015
A small function to check UIAlertView is shown (based on SO answer: http://stackoverflow.com/a/15151877/1492173)
View CheckAlertViewIsShown.swift
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 Sep 14, 2015
Correct sequence of loading UISplitViewController from the storyboard manually
View MYAppDelegate.m
#import "MYAppDelegate.h"
@interface MYAppDelegate () <UISplitViewControllerDelegate>
/...
@property (nonatomic, strong) UISplitViewController* splitViewController;
@end
@implementation MYAppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
@evgeniyd
evgeniyd / MyStringUtils.h
Last active Aug 29, 2015
The behaviour of rangeOfString: you might probably not aware about
View MyStringUtils.h
#import <Foundation/Foundation.h>
@interface MyStringUtils : NSObject
+ (BOOL)confuzion_stringContainsVotedKeywords:(NSString*)input;
+ (BOOL)stringContainsVotedKeywords:(NSString*)input;
@end
You can’t perform that action at this time.