Skip to content

Commit

Permalink
[#98] Add demo app inside SPM target
Browse files Browse the repository at this point in the history
  • Loading branch information
thecatalinstan committed Sep 15, 2022
1 parent 3f9eefa commit d0aa6ee
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 6 deletions.
15 changes: 11 additions & 4 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ let package = Package(
name: "Criollo",
platforms: [.iOS(.v9), .macOS(.v10_10), .tvOS(.v9)],
products: [
.library(
name: "Criollo",
targets: ["Criollo"]
),
.library(name: "Criollo", targets: ["Criollo"]),
.executable(name: "CriolloDemoSwift", targets: ["CriolloDemoSwift"]),
.executable(name: "CriolloDemoObjectiveC", targets: ["CriolloDemoObjectiveC"]),
],
dependencies: [
.package(name:"CocoaAsyncSocket", url: "https://github.com/robbiehanson/CocoaAsyncSocket", .upToNextMinor(from: "7.6.5")),
Expand Down Expand Up @@ -44,5 +43,13 @@ let package = Package(
.headerSearchPath("../../Sources/Criollo/Routing"),
]
),
.executableTarget(
name: "CriolloDemoSwift",
dependencies: ["Criollo"]
),
.executableTarget(
name: "CriolloDemoObjectiveC",
dependencies: ["Criollo"]
)
]
)
17 changes: 17 additions & 0 deletions Sources/CriolloDemoObjectiveC/AppDelegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// AppDelegate.h
//
//
// Created by Cătălin Stan on 16/09/2022.
//

#import <Criollo/Criollo.h>
#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@interface AppDelegate : NSObject <CRApplicationDelegate>

@end

NS_ASSUME_NONNULL_END
36 changes: 36 additions & 0 deletions Sources/CriolloDemoObjectiveC/AppDelegate.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// AppDelegate.m
//
//
// Created by Cătălin Stan on 16/09/2022.
//

#import "AppDelegate.h"

@interface AppDelegate ()

@property (readonly) CRHTTPServer *server;

@end

@implementation AppDelegate

- (instancetype)init {
self = [super init];
if (self) {
_server = [CRHTTPServer new];
}
return self;
}

#pragma mark - CRApplicationDelegate

- (void)applicationDidFinishLaunching:(NSNotification *)notification {
[self.server add:^(CRRequest *request, CRResponse *response, CRRouteCompletionBlock completionHandler) {
[response send:@"Hello world"];
}];

[self.server startListening];
}

@end
15 changes: 15 additions & 0 deletions Sources/CriolloDemoObjectiveC/main.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// main.m
//
//
// Created by Cătălin Stan on 16/09/2022.
//

#import <Criollo/Criollo.h>

#import "AppDelegate.h"

int main(int argc, const char * argv[]) {
return CRApplicationMain(argc, argv, [AppDelegate new]);
}

22 changes: 22 additions & 0 deletions Sources/CriolloDemoSwift/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// AppDelegate.swift
//
//
// Created by Cătălin Stan on 15/09/2022.
//

import Criollo

class AppDelegate: CRApplicationDelegate {

private lazy var server = CRHTTPServer()

// MARK: - CRApplicationDelegate

func applicationDidFinishLaunching(_ notification: Notification) {
server.add { _, res, _ in
res.send("Hello world!")
}
server.startListening()
}
}
10 changes: 10 additions & 0 deletions Sources/CriolloDemoSwift/main.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//
// main.swift
//
//
// Created by Cătălin Stan on 15/09/2022.
//

import Criollo

exit(CRApplicationMain(CommandLine.argc, nil, AppDelegate()))
4 changes: 2 additions & 2 deletions Tests/CriolloTests/CRHTTPSHelperTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ - (NSString *)pathForSampleFile:(NSString *)samplefile;
@implementation CRHTTPSHelperTests

- (NSString *)pathForSampleFile:(NSString *)samplefile {
NSBundle *bundle = [NSBundle bundleForClass:self.class];
return [bundle.resourcePath stringByAppendingPathComponent:samplefile];
const NSString *samplesPath = [@(__FILE__).stringByDeletingLastPathComponent stringByAppendingPathComponent:@"Samples"];
return [samplesPath stringByAppendingPathComponent:samplefile];
}

#pragma mark - Identity
Expand Down

0 comments on commit d0aa6ee

Please sign in to comment.