Xcode Static analysis and nulls

Leave a comment

return header
return (id __nonnull)header;

^(id  _Nullable result, NSError * _Nullable error)
^(SPTMessageTrack *track, NSError *error)

^(id data, NSError *error)
^(SPTMessageAccessToken *token, NSError *error)

fetchAccessTokenWithCallback:(void(^)(id data, NSError *error))block
fetchAccessTokenWithCallback:(void(^)(SPTMessageAccessToken *, NSError *))block

NS_ASSUME_NONNULL_BEGIN
NS_ASSUME_NONNULL_END

Xcode trouble shooting guide

Leave a comment

Here are a list if Xcode trouble shooting scenarios and what they usually mean.

Missing dependency target – file not found

Screen Shot 2017-03-22 at 8.21.55 AM.png

This usually means your subproject is foobar and you need to re-add it.

Screen Shot 2017-03-22 at 8.24.16 AM.png

Go here and follow the instruction on how to do that.

https://agilewarrior.wordpress.com/2017/02/23/how-to-add-ios-xcode-subprojects-abbreviated/

Setting end date instead of computing

Leave a comment

Instead of doing a lot of date and time comparisons, just set the end date of the thing you want.

For example instead of checking to see if a token expires in an hour like this

- (BOOL)hasExpired
{
    if (self.tokenExpirationDate == nil) {
        return YES;
    }
    return [SPTMessageClockUtils oneHourHasPassedFrom:self.tokenExpirationDate];
}

Just set the expiration date on the object itself, and see if it is later than now like this.

- (BOOL)isValid
{
	return ([(NSDate *)[NSDate date] compare:self.expirationDate] == NSOrderedAscending);
}

This simplifies the computing and requires less coding to account for time checks and such.

How to create spherical gradient for title page Illustrator

Leave a comment

Say you want a nice soft glow in the background of your title page.

Screen Shot 2017-02-25 at 2.08.23 PM.png

Do this. Draw a square.

Screen Shot 2017-02-25 at 2.10.38 PM.png

Click Gradient from the Window menu

Screen Shot 2017-02-25 at 2.11.32 PM.png

Then click the gradient button to apply a gradient to your square. And then select ‘radial’ to make it spread out.

Screen Shot 2017-02-25 at 2.12.45 PM.png

Now the trick with making it spread out, it to press ‘g’ and then manually drag the end point of the gradient meter out beyond the square.

Screen Shot 2017-02-25 at 2.19.51 PM.png

Once you learn how to do that, you create create pretty much any gradient you want. Just grab the gradient tool, move it around, and try different things out.

Links that help

Trouble Shooting

If for some reason you find the gradient tool isn’t allowing you to change the gradient (i.e. pressing ‘g’ and then locking you out…toggle the fill stroke switch in the gradient window.

Screen Shot 2017-02-25 at 2.07.13 PM.png

Chances are you have stroke activated when what you really want is fill (or vice versa).

 

How to add iOS Xcode subprojects abbreviated

1 Comment

If you want to add another iOS project to your existing subproject, at a minimum do this. Find the project you want to add

Screen Shot 2017-02-23 at 1.19.43 PM.png

Drag it into your project

Screen Shot 2017-02-23 at 1.20.28 PM.png

Goto the target you want to add it to -> Build Phases.

Add Target Dependency (hit the + sign)

Screen Shot 2017-02-23 at 1.21.54 PM.png

Link Binary With Libraries (+ sign)

Screen Shot 2017-02-23 at 1.22.29 PM.png

Build/Compile. You should now be good to go.

Links that help

https://agilewarrior.wordpress.com/2016/04/04/how-to-add-xcode-subproject/

https://agilewarrior.wordpress.com/2016/12/22/how-to-create-universal-static-library-ios/

How to quickly clear derived data

Leave a comment

Xcode -> Preferences -> Locations -> little grey arrow that is hard to see

Screen Shot 2017-02-23 at 1.18.26 PM.png

Screen Shot 2017-02-23 at 1.18.41 PM.png

Then physically delete the directory in finder

Screen Shot 2017-02-23 at 1.19.00 PM.png

How to share data App Extension

Leave a comment

How to share data between App Extension and Host

Since app extensions run as part of a host application rather than their containing app (i.e. your app extension runs in somebody elses app), data sharing isn’t automatic.

App extensions and hosts can share data via App Groups. App Groups are shared containers both App Extensions and Hosts can use to communicate with each other since no direct communication is allowed.

Setting up an App Group

App Groups are the scheme iOS uses to allow different apps to share data. If you have the right entitlements and proper provisioning, they can access a shared directory outside their normal iOS sandbox.

Create a new SingleView app.

Screen Shot 2017-02-14 at 1.29.21 PM.png

Go Capabilities and turn on App Groups.

Screen Shot 2017-02-14 at 1.29.50 PM.png

Screen Shot 2017-02-14 at 1.29.54 PM.png

Now you can share data like this.

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    NSUserDefaults *myDefaults = [[NSUserDefaults alloc]
                                  initWithSuiteName:@"group.spike.AppGroupNSUserDefaults"];
    [myDefaults setObject:@"foo" forKey:@"bar"];
    NSLog(@"\n\nWrote it!\n\n\n");
}

Add an App Extension

Now let’s add an app extension and try this out. New Target -> iMessage Extension.

Note: This will automatically setup a sub bundle id that should work for you out of the box. Bundle ids are important and this must be nested.

Screen Shot 2017-02-14 at 1.31.31 PM.png

It will also create an entitlements file

Screen Shot 2017-02-14 at 1.31.36 PM.png

Turn on App Groups for your newly created App Extension

Screen Shot 2017-02-14 at 1.32.09 PM.png

And now try reading something from NSUserDefaults written by your container app.

- (void)viewDidLoad {
    [super viewDidLoad];
    NSUserDefaults *myDefaults = [[NSUserDefaults alloc]
                                  initWithSuiteName:@"group.spike.AppGroupNSUserDefaults"];
    NSString *value = [myDefaults objectForKey:@"bar"];
    NSLog(@"\n\n\nvalue: %@\n\n\n", value);
}

 Screen Shot 2017-02-14 at 1.33.26 PM.png

Links that help

https://developer.apple.com/library/content/documentation/General/Conceptual/ExtensibilityPG/ExtensionScenarios.html#//apple_ref/doc/uid/TP40014214-CH21-SW1

http://www.atomicbird.com/blog/sharing-with-app-extensions

Older Entries

%d bloggers like this: