Skip to content

Instantly share code, notes, and snippets.

View max6363's full-sized avatar

Minhaz Panara max6363

View GitHub Profile
let theEventTitleLabel = UILabel()
let newEventLabelSubscriber = Subscribers.Assign(object: theEventTitleLabel, keyPath: \.text)
eventPublisher.subscribe(newEventLabelSubscriber)
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)
[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
- (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) {
#import "HealthKitManager.h"
#import <HealthKit/HealthKit.h>
@interface HealthKitManager ()
@property (nonatomic, retain) HKHealthStore *healthStore;
@end
@implementation HealthKitManager
// shared instance
+ (HealthKitManager *)sharedInstance {
<key>NSHealthUpdateUsageDescription</key>
<string>Allow my app to write data on Health application.</string>
<key>NSHealthShareUsageDescription</key>
<string>Allow my app to access health data from HealthKit.</string>
<key>NSHealthShareUsageDescription</key>
<string>Allow Cubii app to access health data from HealthKit.</string>
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: