Building the user model

To be have a conversation you need to store some information about a user:

  • A user's name
  • A user's JWT
  • Who they are chatting with
  • The conversation ID

To do this you will create a new User Class. From the Xcode menu, select File > New > File.... Select Cocoa Touch Class, name it User with a subclass of NSObject:

Xcode adding file
Xcode adding file

Open User.h declare the properties and functions needed to store the user's information.

@interface User : NSObject

@property NSString *name;
@property NSString *jwt;
@property NSString *chatPartnerName;
@property NSString *conversationId;

-(instancetype)initWithName:(NSString *)name jwt:(NSString *)jwt chatPartnerName:(NSString *)chatPartnerName;



To make things easier for later on there are some static properties on the User type for the users Alice and Bob. Open User.m to implement these alongside the initializer for the class, Replacing ALICE_JWT, BOB_JWT and CONVERSATION_ID with the values you created earlier.

@implementation User

- (instancetype)initWithName:(NSString *)name jwt:(NSString *)jwt chatPartnerName:(NSString *)chatPartnerName
    if (self = [super init])
        _name = name;
        _jwt = jwt;
        _chatPartnerName = chatPartnerName;
        _conversationId = @"CONVERSATION_ID";
    return self;

+ (instancetype)Alice
    return [[User alloc] initWithName:@"Alice" jwt:@"ALICE_JWT" chatPartnerName:@"Bob"];

+ (instancetype)Bob
    return [[User alloc] initWithName:@"Bob" jwt:@"BOB_JWT" chatPartnerName:@"Alice"];