Skip to content

Instantly share code, notes, and snippets.

@DonMag
Last active February 28, 2019 17:40
Show Gist options
  • Select an option

  • Save DonMag/a6fa54512b5fb0fb8a227b996f6ff93b to your computer and use it in GitHub Desktop.

Select an option

Save DonMag/a6fa54512b5fb0fb8a227b996f6ff93b to your computer and use it in GitHub Desktop.
//
// MyTestClass.h
//
// Created by Don Mag on 2/28/19.
//
#import <Foundation/Foundation.h>
#ifndef MyTestClass_h
#define MyTestClass_h
@interface MyTestClass : NSObject
- (void) someMethod:(NSInteger) secondsDelay;
@end
#endif /* MyTestClass_h */
//
// MyTestClass.m
//
// Created by Don Mag on 2/28/19.
//
#import "MyTestClass.h"
@implementation MyTestClass
- (void) someMethod:(NSInteger) secondsDelay {
NSLog(@"SomeMethod executing with secondsDelay of: %ld", (long)secondsDelay);
NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys:
@"Value 1", @"Key1",
@"Value 2", @"Key2",
nil];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(secondsDelay * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
NSLog(@"Posting Notification...");
[[NSNotificationCenter defaultCenter] postNotificationName:@"openBoard" object:nil userInfo:userInfo];
});
}
@end
//
// Use this file to import your target's public headers that you would like to expose to Swift.
//
#import "MyTestClass.h"
//
// ViewController.swift
//
// Created by Don Mag on 2/28/19.
//
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// register to receive the notification
NotificationCenter.default.addObserver(self, selector: #selector(self.openBoard(notification:)), name: Notification.Name("openBoard"), object: nil)
let sDelay = 2
print("Calling someMethod:(NSInteger) secondsDelay - should get notification in \(sDelay) seconds...")
let instanceOfCustomObject: MyTestClass = MyTestClass()
instanceOfCustomObject.someMethod(sDelay)
}
@objc func openBoard(notification: Notification) {
print("Got Notif!")
if let data = notification.userInfo as? [String: String] {
for (k, v) in data {
print("\(k) : \(v)")
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment