thomasguenzel.com

Apps/Programming

Grid View Component for iOS

I’m a huge fan of the new UIStackView in iOS 9, but for one of my projects I did need a view that has a fixed grid layout. It would be completely possible to build this with a collection view or stack views, but I’ve decided to build my own little view.

You can find a zip containing the project here or you can take a look at the source code here.

The Future of Apricum

Apricum started as a small project for creating light shows. I once went out with my laptop plugged in a USB-DMX interface and tried to set everything up for the band contest that was happening this night. After around 5 minutes I noticed that I’m nowhere near being able to have a usable interface for the event. I eventually gave up and used LightJockey 2 that evening.

Unfortunately I’m quite busy at the moment with other projects, so it’ll take some time until a new version of Apricum will be released. It might be that I’ll reprogram the whole app (you’ll be able to open your old projects, and won’t have to buy patch collections again, I promise) as there are a lot of things I’d do different now.

Apricum 1.1 (or maybe even 2.0) won’t have a focus on DMX/Lightning but will be a general purpose patch programming tool. There will be an iOS version a little bit later in 2016.

I hope to bring an update until Q2 2016 but as I’ve made less than 100€ with Apricum, it’s more of a hobby so it might take even longer. (If you want to support me in any way, just contact me :P)

iOS – Displaying a Popover on an iPhone

You can find the source code for this project on GitHub.

As UIPopoverController is deprecated since iOS 9 and I couldn’t find a great example on how to create a popover on an iPhone with iOS 9 I’ve created a small project that demonstrates how to create one.

Here are the important lines of code

- (IBAction)openPopup:(id)sender {
	// popoverViewController is a instance variable of type UIViewController
	if(popoverViewController == nil) {
		popoverViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"popover"];
		
	}
	popoverViewController.preferredContentSize = CGSizeMake(320, 100);
	popoverViewController.modalPresentationStyle = UIModalPresentationPopover;
	UIPopoverPresentationController *popoverController = popoverViewController.popoverPresentationController;
	popoverController.permittedArrowDirections = UIPopoverArrowDirectionDown | UIPopoverArrowDirectionUp;
	popoverController.delegate = self;
	popoverController.sourceView = self.view;
	popoverController.sourceRect = [sender frame];
	
	[self presentViewController:popoverViewController animated:YES completion:nil];
}

-(UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller {
	return UIModalPresentationNone;
}

A Small Speed Comparison – Objective-C and Swift

Today I thought about migrating Apricum to Swift as I did remember the WWDC announcement saying it’s about 50% faster than Objective-C.

Click for the stackoverflow post regarding swift’s performance

I rewrote the necessary parts (just 3 classes) of the Apricum patch programming core in Swift and tested a simple add patch with 1000 different input values (two random numbers for input a and b).
The Objective-C version (which uses the Apricum Core framework) took 0.0087s and the Swift version (not nearly as big as the Apricum framework) took 0.0211s.
I’m not saying that this is a good test as both versions are quite different so I made two similar versions and compared them.

// Objective-C
@interface SimpleAdd : NSObject
-(NSUInteger)add:(NSUInteger)a and:(NSUInteger)b;
@end

@implementation SimpleAdd

-(NSUInteger)add:(NSUInteger)a and:(NSUInteger)b {
	return a+b;
}

@end

int main(int argc, const char * argv[]) {
	@autoreleasepool {
		SimpleAdd *add = [[SimpleAdd alloc] init];
		
		NSDate *start = [NSDate date];
		
		for (NSUInteger i = 0; i < 100000000; i++) {
			NSUInteger a = arc4random()%(UINT32_MAX/100);
			NSUInteger b = arc4random()%(UINT32_MAX/100);
			NSUInteger res = [add add:a and:b];
		}
		
		NSDate *end = [NSDate date];
		printf("Duration %f\n",[end timeIntervalSinceDate:start]);

	}
    return 0;
}
// Swift
class SimpleAdd {
	func add(a: UInt32, b: UInt32) -> UInt32 {
		return a + b;
	}
}

let add = SimpleAdd();

let start = NSDate();

for _ in 0...100000000 {
	let numA = arc4random() % (UINT32_MAX/100);
	let numB = arc4random() % (UINT32_MAX/100);
	let res = add.add(numA, b: numB);
}

let end = NSDate();

let dif = end.timeIntervalSinceDate(start);

print("Duration: \(dif)");

Now Objective-C took 4.1378s and Swift 4.3653s, which doesn’t seem like a big difference. But Swift doesn’t have dynamic method calls (well it supports the target/actions, but only by using Objective-C) unlike Objective-C where every call to a NSObject is a dynamic method call.

I personally will continue to use Objective-C over Swift, not because Objective-C is in one arbitrary test 0.2275s faster than Swift. It’s mainly because I’m not the biggest fan of the Swift programming language. It’s easier to read if you know Java/JavaScript already, which is a big advantage if you want to get into iOS Development and already know one of them, but I’m missing the features I love about Objective-C.
Additionally the freedom to choose whether you check objects for nil or just call a method is far, far better than those nested ‘if let’ checks you see all over Swift code. Most of the time the code I’ve read ends up using var xyz: ExampleType! which is even worse, as it’ll end up crashing your app if xyz isn’t set somehow, which although it should not happen, might happen.

Another part I really dislike is the lack of backward compatibility in Swift. While programming Objective-C, it happened once, that a change has been made that needed code changes. That was the migration to ARC, where you can still (to this day) mix ARC code with non-ARC code.
The complete opposite is Swift, where changes are frequent and mandatory. I was working on a project and over night Xcode updated to version 7.0 with a slightly different Swift syntax, making it necessary to change small parts all over the project (Fortunately one team member already did change most parts to the new syntax). This incident drove me away from using Swift for big projects, as I can compile more than 5 year old Objective-C code, but can’t compile Swift code I wrote a few months ago.

Although it probably sounds like it, I don’t hate Swift. Every programming language has pros and cons and you have to pick the one that matches your requirements and personal preferences. Swift is quite simple (I’d put it somewhere in the middle between JavaScript and Java) yet quite efficient, which actually isn’t that important anymore. Whether you wait 1ms or 2ms for your app to load doesn’t make any difference and if there are some parts that need to be faster you can still write them in C (and therefore also directly in assembler) to speed them up.

Today Process Timer got released. You can find it here!

UIActivityViewController NSData with Filename

In one of my upcoming apps I want the user to be able to send a file using the UIActivityViewController. As I create the NSData object during runtime, I passed the data to the activity view like this:

NSData *someData = /*...*/;
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:@[someData] applicationActivities:nil];

But unfortunately this resulted in something like this:

without_filename

So in order to get a filename instead of “Attachment-1” I create a file in the temporary directory and pass the activity view the url.

// create url
NSURL *url = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingString:@"My File.txt"]];
NSData *data = /*...*/;
// write data
[dataToWrite writeToURL:url atomically:NO];

// create activity view controller
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:@[url] applicationActivities:nil];
[activityViewController setCompletionWithItemsHandler:^(NSString *activityType, BOOL completed, NSArray *returnedItems, NSError *activityError) {
	//Delete file
	NSError *errorBlock;
	if([[NSFileManager defaultManager] removeItemAtURL:url error:&errorBlock] == NO) {
		NSLog(@"error deleting file %@",error);
		return;
	}
}];

As a result, the messages screen looks now like this:

with_filename

Apricum now available

I have developed a new app for mac. Developed with lighting control in mind, it did evolve into a patch programming tool for Mac. You can find more informations on it’s website:

Apricum Website

Search and Replace 1.2

Today a new version of Search and Replace for Mac OS X has been reviewed and approved for the App Store. It has a new file extension filter and you can enter a small description for every file. You can update or buy it here.

Easy GPS Tracker

After more than 1 year I finally managed to update DrunkTracker, and as I want this App to be used not only by teenagers I have renamed it to Easy GPS Tracker. It’s mainly an interface update to iOS 7 and the 4-inch screen of the newer iPhones. Look here for more information: Easy GPS Tracker

Search and Replace on the Mac App Store

Just a few minutes ago my newest app, Search and Replace, went online! It’s a helpful tool if you need to perform search and replace operations on multiple files. You can also use regular expressions for complex operations.

Take a look at it here.

« Older posts

© 2016 thomasguenzel.com

Theme by Anders NorenUp ↑