Posts

iPhone Simulator Zombies, how to destroy them

Image
If you're on the same machine for years, and multiple versions of OSX and Xcode, likely you'll build up a large list of simulators that show when you want to select a simulator to run your app on.

As of Xcode 9 this became a breaking feature (at least for me).  Xcode had a hard time scrolling through the massive list, so searching online found a few solutions, and I just compiled them together here:

1) Remove yourself from iOS teams you no longer work on.

As far as I can tell this is a recent addition, as before you had to ask the team admin to remove you.


2) Remove the profiles from your machine (might as well nuke them all).

The path to do this is here (credit goes to Alex from the Houston iPhone Developer UG):


3) Remove all the simulators you no longer need, I'd say remove all of them then reinstall the ones you want.

In Xcode go Window -> Devices and Simulators

Unfortunately there's no "Delete All" or select all feature.  You'll have to manually de…

awakeFromNib, layoutSubviews, dequeueReusableCellWithIdentifier and what happens in what order

If you have customized code in your UITableViewCell subclass like myself, you usually have someIf you have customized code in your UITableViewCell subclass like myself, you usually have some startup code for the cell, usually setting some constraints, or colors of text, default placeholder, etc. It generally doesn't matter whether this code goes in awakeFromNib or layoutSubviews, as long as what you do after dequeueReusableCellWithIdentifier doesn't depend on logic in either of these startup methods.In the case where it does, you need to know which one happens in which order, in my case I'm using a custom UITextView that has placeholder text, via a nice blog post on how to do that:https://grokswift.com/uitextview-placeholder/The issue was that when opening a form to fill out for a new document the text is empty, so you need placeholder text. On top of this I have a label that needs to show (alpha = 1) when text from the user is inputted. When no text exists in the TextV…

Draw a red border around your UIView for debugging purposes

Image
A lot of the times, you're dealing with UITextViews and UITextFields that have the sameA lot of the times, you're dealing with UITextViews and UITextFields that have the same white background and border as the superviews they sit on top of. It's helpful every now and then to make sure they're obeying the constraints you want them to have. In my case, I made a self-contained UITextView that has a placeholder functionality but the textView wasn't constraining to the size of its container view.DOH!Ahh... needed better constraints:func applyConstraintsToTextView() { if let validTextView = self.placeholderTextView { let viewsDictionary = ["textView":validTextView] self.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|[textView]|", options: [], metrics: nil, views: viewsDictionary)) self.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|[textView]|", options: [], metrics: nil, v…

Quickly add a simple UIActivityIndicator to your screen

Sometimes you need to quickly throw a progress indicator over your view while something processesSometimes you need to quickly throw a progress indicator over your view while something processes (hopefully in the background).I've found this code to be useful for that situation. Apply to your needs.UIActivityIndicatorView *activityIndicatorView = [[UIActivityIndicatorView alloc] initWithFrame:self.view.frame]; activityIndicatorView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge; activityIndicatorView.backgroundColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.5]; [self.view addSubview:activityIndicatorView]; [activityIndicatorView startAnimating]; [self.presentingViewController dismissViewControllerAnimated:YES completion:^{ dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0ul); dispatch_async(queue, ^{ // do your processing in the background here dispatch_sync(dispatch_get_main_queue(), ^{…

Finder shortcut to open a directory path

Image
I find myself using this a lot after a co-worker showed me. Basically, if you come across a directory path you need to get to, like to drop files into a folder or delete file, whatever, instead of manually clicking each directory to get to the destination, you can copy and paste the path into finder via

   ⌘ + Shift + G

Modularize your UIImagePickerController usage in Swift

When you run across quick tutorials or answers on using UIImagePickerController the majority have you When you run across quick tutorials or answers on using UIImagePickerController the majority have you simply instantiating, containing, delegating and using it inside your UIViewController. As with most coding examples this is for demonstration purposes only, you should always, always abstract out functionality into reusable pieces in any application. The most obvious reason is that if one view controller needs the image picking functionalities, it's a safe bet that another will at some point. If not, well you'll probably run across another need for it in another application, much easier to strip out the code if it's self-containined in one class.
The history of this code has been in Objective-C and it's served me well in more than one app, here I'm converting and using it in Swift for the first time in an app I'm currently building.
To start, create a c…

Prefer Swift's for-in loop over traditional C for loop

I'm sure most of us started our first programming adventures in C. How many timesI'm sure most of us started our first programming adventures in C.How many times have you writtenfor (int i = 0; i < blah; i++) or something similar in countless methods, functions, etc.?In C, C++, Javascript, Java, it's ubiquitous.Then I came upon the most glorious programming language ever created, Rubyfor index in 0..5 puts "Value of local variable is #{i}" end This is obviously equivalent to:for (int index = 0; i <= 5; i++) The ease of reading should be obvious in Ruby's typical verbosity. Not that any programmer worth his/her salt can't immediately decipher a traditional for loop.The idea though is to flow code in a way we read natural language.So it was no suprise that Swift adopted this for-in loop pattern, and in all cases you should prefer to use this format over the C for loop.Here's Swift's for-infor index in 0...5 { print("current in…