This application is modifying the autolayout engine from a background thread after the engine was accessed from the main thread. This can lead to engine corruption and weird crashes.

Leave a comment

If you ever get this error while doing autolayout, catch it by setting a symbolic break point.

Screen Shot 2017-01-13 at 9.01.54 AM.png

Can also add an action like this

Screen Shot 2017-01-13 at 9.09.40 AM.png

And then see in output like this

Screen Shot 2017-01-13 at 9.10.43 AM.png

The way to fix it is to dispatch things on the mainthread and not in the background.

dispatch_async(dispatch_get_main_queue(), ^{
    // code here

How to UICollectionViewDelegateFlowLayout

Leave a comment

To control the height of your UICollectionView cells and such, control drag the yellow cube ‘Flow layout’ from your storyboard into your implementation file.

Screen Shot 2017-01-13 at 6.59.10 AM.png

Screen Shot 2017-01-13 at 7.02.38 AM.png

Implement the UICollectionViewDelegateFlowLayout

Screen Shot 2017-01-13 at 7.01.19 AM.png

Assign your outlet to your collection view layout

Screen Shot 2017-01-13 at 7.06.29 AM.png

And then set your height as you see appropriate

Screen Shot 2017-01-13 at 7.10.03 AM.png

Code for copy paste


#pragma UICollectionViewDelegateFlowLayout

- (CGSize)collectionView:(UICollectionView *)collectionView
                  layout:(UICollectionViewLayout *)collectionViewLayout
  sizeForItemAtIndexPath:(NSIndexPath *)indexPath
    return CGSizeMake(collectionView.frame.size.width, self.collectionFlowLayout.itemSize.height);

How to write an NSArray to disk

Leave a comment

- (void)writeToDiskArray:(NSArray *)json
    //Creating a file path under iOS:
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];

    NSString *filename = [documentsDirectory stringByAppendingPathComponent:@"artists.txt"];
    NSDictionary *artists = [json valueForKey:@"artists"];

    NSData *data = [NSKeyedArchiver archivedDataWithRootObject:artists];
    [data writeToFile:filename atomically:YES];

    NSLog(@"\n\n\n\nWriting data to:%@\n\n\n\n", filename);


UISearchBar autolayout and height

Leave a comment

Sometimes you don’t want to pin your UI components all the way to the outer edges. Sometimes you just want to set the height as a constraint instead of pinning to the bottom. Like in this UISearchBar

Screen Shot 2017-01-12 at 5.27.01 AM.png

Screen Shot 2017-01-12 at 5.27.12 AM.png

Instead of setting the bottom constraint. Set the height to be fixed at 44. This is better.

Another trick you can do when doing autolayout is to select the two elements you want to constrain, and control drag them between them in the side layout view display.

Screen Shot 2017-01-12 at 5.27.46 AM.png

Screen Shot 2017-01-12 at 5.29.37 AM.png

How to choose which element to pin to when doing Autolayout

Leave a comment

When pinning constraints via autolayout, press the drop down triangle to choose which element you want to pin to.

Screen Shot 2017-01-11 at 11.04.32 AM.png

Thank you Kevski.

How to gitignore sub projects

Leave a comment

If you have dirty subprojects (say in a project named core) do this

Screen Shot 2017-01-11 at 1.51.22 PM.png

How top instantiate ViewControllers from storyboards with ContainViews

Leave a comment

One way to instantiate ViewControllers is to do it all programmatically like this

Screen Shot 2017-01-11 at 1.37.47 PM.png

Screen Shot 2017-01-11 at 1.38.01 PM.png

But another way to do it is by embedding the ViewController directly in the parent viewController and loading it from there.

Go to you parent viewController (the one you want to have childViewControllers that you swap in and out) and add a ‘ContainerView’

Screen Shot 2017-01-11 at 1.40.52 PM.png

This will give you a new ViewController with a segue out of the parent. Delete the VC they give you. Create a new one. Create a ViewController.

Control drag from the ContainView to the new VC you just created and select embed.

Screen Shot 2017-01-11 at 1.44.20 PM.png

Bind the ViewController to that new ViewController you just dragged out, and then load it like this.

Screen Shot 2017-01-11 at 1.42.35 PM.png

Same thing as we did before. But just another way of doing it.


Older Entries Newer Entries

%d bloggers like this: