Skip to content

Commit

Permalink
Fix objc bridging and add example (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
msanders committed Jan 3, 2018
1 parent ae44602 commit 2370c08
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
29 changes: 29 additions & 0 deletions Examples/iOS/Bridging.m
@@ -0,0 +1,29 @@
//
// Bridging.m
// TrueTime-iOS
//
// Created by Michael Sanders on 1/2/18.
// Copyright © 2018 Instacart. All rights reserved.
//

@import TrueTime;

@interface Bridging : NSObject
@end

@implementation Bridging

- (void)testBridging {
TrueTimeClient *client = [TrueTimeClient sharedInstance];
[client startWithHostURLs:@[(id)[NSURL URLWithString:@"time.apple.com"]]];

NSDate *now = [[client referenceTime] now];
NSLog(@"True time: %@", now);
[client fetchIfNeededWithSuccess:^(NTPReferenceTime *referenceTime) {
NSLog(@"True time: %@", [referenceTime now]);
} failure:^(NSError *error) {
NSLog(@"Error! %@", error);
}];
}

@end
8 changes: 4 additions & 4 deletions Sources/TrueTime.swift
Expand Up @@ -21,10 +21,10 @@ import Result

@objc(NTPReferenceTime)
public final class ReferenceTime: NSObject {
public var uptimeInterval: TimeInterval { return underlyingValue.uptimeInterval }
public var time: Date { return underlyingValue.time }
public var uptime: timeval { return underlyingValue.uptime }
public func now() -> Date { return underlyingValue.now() }
@objc public var uptimeInterval: TimeInterval { return underlyingValue.uptimeInterval }
@objc public var time: Date { return underlyingValue.time }
@objc public var uptime: timeval { return underlyingValue.uptime }
@objc public func now() -> Date { return underlyingValue.now() }

public convenience init(time: Date, uptime: timeval) {
self.init(FrozenReferenceTime(time: time, uptime: uptime))
Expand Down
4 changes: 4 additions & 0 deletions TrueTime.xcodeproj/project.pbxproj
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
05CEA58A1FFC5AC5002624AC /* Bridging.m in Sources */ = {isa = PBXBuildFile; fileRef = 05CEA5871FFC5A80002624AC /* Bridging.m */; };
2800902E1D444AD5004C788E /* SwiftCheck.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2800902D1D444AD5004C788E /* SwiftCheck.framework */; };
2800904F1D444B64004C788E /* TrueTime.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 287C37B41D4419F800084D47 /* TrueTime.framework */; };
280090561D444B85004C788E /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 280090301D444AE5004C788E /* Nimble.framework */; };
Expand Down Expand Up @@ -129,6 +130,7 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
05CEA5871FFC5A80002624AC /* Bridging.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = Bridging.m; sourceTree = "<group>"; };
2800902D1D444AD5004C788E /* SwiftCheck.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SwiftCheck.framework; path = Carthage/Build/iOS/SwiftCheck.framework; sourceTree = "<group>"; };
280090301D444AE5004C788E /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Nimble.framework; path = Carthage/Build/Mac/Nimble.framework; sourceTree = "<group>"; };
280090311D444AE5004C788E /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Quick.framework; path = Carthage/Build/Mac/Quick.framework; sourceTree = "<group>"; };
Expand Down Expand Up @@ -315,6 +317,7 @@
287485581DB140F70020B777 /* Default-568h@2x.png */,
280090801D454A9F004C788E /* AppDelegate.swift */,
28F30A3D1DC1374700CCF4F0 /* ViewController.swift */,
05CEA5871FFC5A80002624AC /* Bridging.m */,
280090811D454A9F004C788E /* Assets.xcassets */,
280090821D454A9F004C788E /* Info.plist */,
);
Expand Down Expand Up @@ -960,6 +963,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
05CEA58A1FFC5AC5002624AC /* Bridging.m in Sources */,
28F30A3F1DC1374D00CCF4F0 /* ViewController.swift in Sources */,
280090831D454A9F004C788E /* AppDelegate.swift in Sources */,
);
Expand Down

0 comments on commit 2370c08

Please sign in to comment.