Categories
Development

Xcode wackiness

Let’s just say I have a protocol that conforms to NSObject and NSCoping. It was something like this.

@protocol MyProtocol <NSObject, NSCopying>

- (void)example_doSomethingWithMyProtocol:(id<MyProtocol>)protocol;

@end

And also have a class, that has a method, and conforms to the protocol with a category.

@interface MyClass : NSObject <NSCopying>

@property (nonnull, nonatomic, copy) NSString *myString;

- (instancetype)initWithString:(NSString *)string;

- (NSString *)doSomethingWithMyClass:(MyClass *)myClass;

@end

@interface MyClass (Example) <MyProtocol>

@end

And the implementation looks something like this

@implementation MyClass

- (instancetype)initWithString:(NSString *)string
{
    self = [super init];
    if (self) {
        _myString = string;
    }
    return self;
}

-(NSString *)doSomethingWithMyClass:(MyClass *)myClass
{
    return [NSString stringWithFormat:@"%@ + %@", self.myString, myClass.myString];
}

- (nonnull id)copyWithZone:(nullable NSZone *)zone {
    return self;
}

@end

@implementation MyClass (Example)

- (NSString *)example_doSomethingWithMyProtocol:(id<MyProtocol>)protocol
{
    if (![protocol isKindOfClass:[MyClass class]]){
        return nil;
    }

    return [self doSomethingWithMyClass:protocol];
}

@end

So at this point, Xcode is happy. No warnings and no errors.

Let’s start the wackiness.

Let look at our protocol again. I don’t think we need to require NSCopying anymore, so let’s remove it. So our protocol now looks like this.

@protocol MyProtocol <NSObject>

- (void)example_doSomethingWithMyProtocol:(id<MyProtocol>)protocol;

@end

Let’s build and compile.

Whats this 1 warning! Heres the warning.

Why didn’t this warning show up before removing NSCopying. ¯\_(ツ)_/¯ You could just cast it, sure but where is the fun in that. Ok lets rest our protocol to the original. Yay, the warning wen’t way. Let’s now remove NSCopying from our class.

@interface MyClass : NSObject
...
@end

Oh, no we have a new warning.

This one has a “fix it” so let’s apply it. It add a copy with zone, so let’s just return self. If you noticed from before we already have a copy with zone method. We’re going to compile now, ok no errors but we have a new linker warning.

instance method 'copyWithZone:' in category from /.../MyClass.o overrides method from class in /.../MyClass.o

Oh dear, that doesn’t look good. Why didn’t it find the original when implementation. ¯\_(ツ)_/¯

What was the point of this exercise, well nothing and what’s some conclusions we can make. Well we can conclude that Xcode is wacky and does wacky things but if you work with Xcode, you already knew that. If you want the code from this experiment to experience the wackiness for yourself, you can get it here.

Categories
Travel

Japan for less then $1000

It’s alway been a dream of mine to go to Japan but I’m not a fan of spending money. I hear Japan is expensive. I want to spend less than $1000 out of pocket for a two week trip.

How I plan to do this, three words, credit card points. Heres a breakdown of my points at the time of writing.

  • Chase – 112,000
  • Amex – 60,000
  • Marriott – 13,000

Flights look to be about $800, since I have the Chase Sapphire Reserve I get 1.5 points per cent on travel, so ~52,000 points for the plane ticket. I also looked into transferring my points to an airline and I don’t get any more bang for the buck that way.

So If I use my chase point to get the flight that leaves the hotel. I need to think about the itinerary and what I want to see before I can make a decision on the hotel. However if I transfer all my points from remaining Chase and Amex to Marriott I’ll have 110,000. That will get me nowhere. Marriotts are really expensive in Japan.

Let’s look at booking the hotel through Amex. With my Amex points I can stay at trip adviser 4 star hotel for 5 nights in Tokyo. 5 nights down 9 to go. Ok, with my remaining Chase points I do 4 nights in Kyoto, 2 nights in Hiroshima, and 2 nights in Osaka.

Ok that just leaves when transportation between those cities, food, and things when I’m there which should come in under $1000. So I guess I’m going to Japan.

Categories
Uncategorized

Hello world!

Just setting up my blog. I can’t believe how easy this was to setup and why I didn’t do it sooner. Welcome to my blog, I don’t know what I’m going to be posting here. Probably random thoughts, tech related things, and/or tutorials. We’ll see how it goes.

Just about me, I’m Justin Anderson. I work at Twitter and I mostly do iOS development but I dabble in Android, web and backend. I’ve been doing iOS since iOS 4 and maybe before. I currently have an app in the store, Hexd. I also have a joke website artisanpasswords.com.