Skip to content

Instantly share code, notes, and snippets.

View evgeniyd's full-sized avatar
🌚

Yevhen Dubinin evgeniyd

🌚
View GitHub Profile
@evgeniyd
evgeniyd / PrintFontFamilyNames.m
Created June 8, 2015 11:01
Printing all the font families and names available at the runtime of an application. Helpful for troubleshooting font issues. Reference: http://codewithchris.com/common-mistakes-with-adding-custom-fonts-to-your-ios-app/
// copy-paste at the begining of application:didFinishLaunchingWithOptions:
for (NSString* family in [UIFont familyNames])
{
NSLog(@"%@", family);
for (NSString* name in [UIFont fontNamesForFamilyName: family])
{
NSLog(@" %@", name);
}
@evgeniyd
evgeniyd / MyStringUtils.h
Last active August 29, 2015 14:26
The behaviour of rangeOfString: you might probably not aware about
#import <Foundation/Foundation.h>
@interface MyStringUtils : NSObject
+ (BOOL)confuzion_stringContainsVotedKeywords:(NSString*)input;
+ (BOOL)stringContainsVotedKeywords:(NSString*)input;
@end
@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 {
@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 / 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 / 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 / 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 / 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 / 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 / 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() {
}