Today I found something cool in the form of NSExpression.
I wanted to be able to evaluate arithmetic represented as an NSString without having to write too much code. Using NSExpression it's a two step operation.
NSExpression *expression = [NSExpression expressionWithFormat:@"9+4"];
// result is a NSNumber
id result = [expression expressionValueWithObject:nil context:nil];
I wanted to have a go at creating a half modal slide transition. The intention for this is if you want the user to be able to see the contents of the previous view controller and a partial amount of the one you've just pushed on.
Check out JLPeekModal on Github.
There are a few options which I need to refactor to allow for more obvious customisation. I'm hoping the code is readable enough for that already :)
Recently I needed a way to use a custom icon font (e.g. Font Awesome and save the results out as an image. It turns out this isn't too hard (with some help from Stackoverflow).
I've written a gist to save out a UILabel as a UIImage.
This category makes a few assumptions:
- You're only creating an image for a single letter from an icon font
- You want to save out the image to file and load from that
Once an image is created it will be loaded each and every time. If you're going to be actively changing the icon font I'd recommend commenting out the saving code. I'd also recommend putting in a job on app load to clear out the PNG files created every couple of weeks in case of updates.
The creation of a PNG file for loading later isn't really required as the creation of a UIImage is very fast.
I'm currently working on an Interval timer app. In order to make it easier on myself I wrote a timer that suited my needs.
I've taken out that timer and put it on Github.
Hopefully it may come across as useful to someone besides myself!
# Implement the protocol
@interface YourClass <IntervalTimerDelegate>
# Create a timer and start
self.timer = [[IntervalTimer alloc] initWithTimeInterval:[interval.time doubleValue] delegate:self];
# Use the delegate method
This is a simple one that I didn't even think about until I started my new job.
When using Core Data and generating your object models make sure to create a category for them. This allows you to create all your extra methods in a file that won't be replaced if you have to generate your object model again.
e.g. If I have a model called Workout
@interface Workout (Extra)
I find it's a really nice pattern to use as I've found when I'm developing something new my data models tend to change quite frequently. This saves trying to copy and paste my changes over and over again.