Skip to content

Instantly share code, notes, and snippets.

View indyfromoz's full-sized avatar
🏠
Working from home

Indrajit Chakrabarty indyfromoz

🏠
Working from home
View GitHub Profile
@indyfromoz
indyfromoz / UITableView-RowSelection.m
Created August 26, 2013 15:12
Selecting a row of a UITableView after it is loaded
// The performSelection: method is a "hack". The default row should be selected
// after the last row is selected in the table view
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self performSelector:@selector(selectDefaultTableRow) withObject:nil afterDelay:0.5];
}
@indyfromoz
indyfromoz / FontList.m
Created September 5, 2013 11:30
List all the fonts in an iOS app
NSArray *familyNames = [[NSArray alloc] initWithArray:[UIFont familyNames]];
NSArray *fontNames;
NSInteger indFamily, indFont;
for (indFamily=0; indFamily<[familyNames count]; ++indFamily)
{
NSLog(@"Family name: %@", [familyNames objectAtIndex:indFamily]);
fontNames = [[NSArray alloc] initWithArray:
[UIFont fontNamesForFamilyName:
[familyNames objectAtIndex:indFamily]]];
for (indFont=0; indFont<[fontNames count]; ++indFont)
BOOL PSPDFIsUIKitFlatMode(void) {
static BOOL isUIKitFlatMode = NO;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber_iOS_7_0) {
PSPDFAssertIfNotMainThread();
// If your app is running in legacy mode, tintColor will be nil - else it must be set to some color.
if (UIApplication.sharedApplication.keyWindow) {
isUIKitFlatMode = [UIApplication.sharedApplication.delegate.window performSelector:@selector(tintColor)] != nil;
@indyfromoz
indyfromoz / gist:7033012
Created October 17, 2013 22:02
Prevent Xcode from updating
On the versions you don’t wish to auto-update, remove Xcode.app/Contents/_MASReceipt/receipt
@indyfromoz
indyfromoz / Alter-Collation.sql
Created October 31, 2013 05:34
Alter the collation of a SQL database
USE master;
GO
ALTER DATABASE MyOptionsTest
COLLATE French_CI_AS ;
GO
--Verify the collation setting.
SELECT name, collation_name
FROM sys.databases
WHERE name = N'MyOptionsTest';
@indyfromoz
indyfromoz / UIImageView+DeviceOrientation.m
Last active January 1, 2016 08:19
Update background image of a view based on device orientation
/*
Add this in a view
*/
- (void)viewWillAppear:(BOOL)animated {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil];
}
// Update the background image if the device is an iPad and its orientation changed
- (void)orientationChanged:(NSNotification *)notification {
@indyfromoz
indyfromoz / node-file-watcher.js
Created December 25, 2013 06:09
Watches a file for any changes
fs.watch('any-folder-you-want', function (event, filename) {
console.log('event: ' + event);
if (filename) {
console.log('filename: ' + filename);
} else {
console.log('filename unknown');
}
});
@indyfromoz
indyfromoz / fade-in-subview.m
Created December 29, 2013 01:56
Fade in a newly added subview
[fadingView setAlpha:0.0];
[containerView addSubview:fadingView];
[UIView beginAnimations:nil context:nil];
[fadingView setAlpha:1.0];
[UIView commitAnimations];
// Remove from superView
[UIView animateWithDuration:0.2
animations:^{viewOut.alpha = 0.0;}
completion:^(BOOL finished){[viewOut removeFromSuperview];}];
@indyfromoz
indyfromoz / uinavigationbar-noshadown.m
Created January 15, 2014 14:01
Remove single pixel shadow from UINavigationBar
[self.navigationController.navigationBar setShadowImage:[[UIImage alloc] init]];
[self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc]init] forBarMetrics:UIBarMetricsDefault];

Thoughts on Swift 2 Errors

When Swift was first announced, I was gratified to see that one of the (few) philosophies that it shared with Objective-C was that exceptions should not be used for control flow, only for highlighting fatal programming errors at development time.

So it came as a surprise to me when Swift 2 brought (What appeared to be) traditional exception handling to the language.

Similarly surprised were the functional Swift programmers, who had put their faith in the Haskell-style approach to error handling, where every function returns an enum (or monad, if you like) containing either a valid result or an error. This seemed like a natural fit for Swift, so why did Apple instead opt for a solution originally designed for clumsy imperative languages?

I'm going to cover three things in this post: