This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let theEventTitleLabel = UILabel() | |
let newEventLabelSubscriber = Subscribers.Assign(object: theEventTitleLabel, keyPath: \.text) | |
eventPublisher.subscribe(newEventLabelSubscriber) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Notification.Name { | |
static let newEvent = Notification.Name("new_event") | |
} | |
struct Event { | |
let title: String | |
let scheduledOn: Date | |
} | |
let eventPublisher = NotificationCenter.Publisher(center: .default, name: .newEvent, object: nil) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[1, 2, 3] | |
.publisher | |
.sink(receiveCompletion: { completion in | |
switch completion { | |
case .failure(let error): | |
print("Something went wrong: \(error)") | |
case .finished: | |
print("Received Completion") | |
} | |
}, receiveValue: { value in |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)requestToWriteDataWithFinishBlock:(void (^)(NSError *error))finishBlock | |
{ | |
// write permission | |
NSArray *writeTypes = @[ | |
[HKObjectType quantityTypeForIdentifier:HKQuantityTypeIdentifierStepCount] | |
]; | |
[self.healthStore requestAuthorizationToShareTypes:[NSSet setWithArray:writeTypes] | |
readTypes:nil | |
completion:^(BOOL success, NSError * _Nullable error) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "HealthKitManager.h" | |
#import <HealthKit/HealthKit.h> | |
@interface HealthKitManager () | |
@property (nonatomic, retain) HKHealthStore *healthStore; | |
@end | |
@implementation HealthKitManager | |
// shared instance | |
+ (HealthKitManager *)sharedInstance { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<key>NSHealthUpdateUsageDescription</key> | |
<string>Allow my app to write data on Health application.</string> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func sizeWithIndex(_ index: Int) -> CGFloat { | |
switch index { | |
case 7: | |
return 0.010 | |
case 3, 11: | |
return 0.007 | |
case 1, 5, 9, 13: | |
return 0.005 | |
default: |
NewerOlder