Repository: realm/realm-swift
File: Realm/RLMApp.mm (Objective-C++)

Code before:

- (NSDictionary<NSString *, RLMUser *> *)allUsers {
    NSMutableDictionary *buffer = [NSMutableDictionary new];
    for (auto&& user : _app->sync_manager()->all_users()) {
        NSString *identity = @(user->identity().c_str());
        buffer[identity] = [[RLMUser alloc] initWithUser:std::move(user) app:self];
    }
    return buffer;
}

- (RLMUser *)currentUser {
    if (auto user = _app->sync_manager()->get_current_user()) {
        return [[RLMUser alloc] initWithUser:user app:self];
    }
    return nil;
}

- (RLMEmailPasswordAuth *)emailPasswordAuth {
    return [[RLMEmailPasswordAuth alloc] initWithApp: self];
}

- (NSString *)baseUrl {
    return getOptionalString(_app->get_base_url()) ?: RLMStringViewToNSString(_app->default_base_url());
}

- (void)updateBaseUrl:(NSString *)baseURL
           completion:(RLMOptionalErrorBlock)completionHandler {
    auto completion = ^(std::optional<app::AppError> error) {
        if (error) {
            return completionHandler(makeError(*error));
        }

        completionHandler(nil);
    };
    return RLMTranslateError([&] {
        return _app->update_base_url(baseURL.UTF8String, completion);
    });
}

- (void)loginWithCredential:(RLMCredentials *)credentials
                 completion:(RLMUserCompletionBlock)completionHandler {
    auto completion = ^(std::shared_ptr<SyncUser> user, std::optional<app::AppError> error) {
        if (error) {
            return completionHandler(nil, makeError(*error));
        }

        completionHandler([[RLMUser alloc] initWithUser:user app:self], nil);
    };
    return RLMTranslateError([&] {
        return _app->log_in_with_credentials(credentials.appCredentials, completion);
    });

Review comment (suggestion):
Can I pass in `nil` here and if I do, would `.UTF8String` throw or return `nil` as well? The core API supports supplying an empty string to reset back to the default url, so we should consider allowing this in the SDK API as well.

Code after:
}

- (NSDictionary<NSString *, RLMUser *> *)allUsers {
    NSMutableDictionary *buffer = [NSMutableDictionary new];
    for (auto&& user : _app->all_users()) {
        NSString *user_id = @(user->user_id().c_str());
        buffer[user_id] = [[RLMUser alloc] initWithUser:std::move(user)];
    }
    return buffer;
}

- (RLMUser *)currentUser {
    if (auto user = _app->current_user()) {
        return [[RLMUser alloc] initWithUser:user];
    }
    return nil;
}

- (RLMEmailPasswordAuth *)emailPasswordAuth {
    return [[RLMEmailPasswordAuth alloc] initWithApp:_app];
}

- (NSString *)baseUrl {
    return getOptionalString(_app->get_base_url()) ?: RLMStringViewToNSString(_app->default_base_url());
}

- (void)updateBaseURL:(NSString * _Nullable)baseURL completion:(nonnull RLMOptionalErrorBlock)completionHandler {
    auto completion = ^(std::optional<app::AppError> error) {
        if (error) {
            return completionHandler(makeError(*error));
        }

        completionHandler(nil);
    };
    return RLMTranslateError([&] {
        NSString *url = (baseURL ?: @"");
        NSString *newUrl = [url stringByReplacingOccurrencesOfString:@"/" withString:@"" options:0 range:NSMakeRange(url.length-1, 1)];
        return _app->update_base_url(newUrl.UTF8String, completion);
    });
}

- (void)loginWithCredential:(RLMCredentials *)credentials
                 completion:(RLMUserCompletionBlock)completionHandler {
    auto completion = ^(std::shared_ptr<app::User> user, std::optional<app::AppError> error) {
        if (error) {
            return completionHandler(nil, makeError(*error));
        }

        completionHandler([[RLMUser alloc] initWithUser:user], nil);
    };
    return RLMTranslateError([&] {