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
@protocol NSCoding | |
- (void)encodeWithCoder:(NSCoder *)aCoder; | |
- (id)initWithCoder:(NSCoder *)aDecoder; // NS_DESIGNATED_INITIALIZER | |
@end |
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
xcrun simctl list | grep "Booted" |
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
[[EKEventStore new] requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) { | |
if (granted) { | |
NSLog(@"Access to calendar granted"); | |
} else { | |
NSLog(@"No access to calendar"); | |
} | |
}]; |
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
NSArray *calendars = [[EKEventStore new] calendarsForEntityType:EKEntityTypeEvent]; |
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
NSPredicate *predicate = [[EKEventStore new] predicateForEventsWithStartDate:startDate | |
endDate:endDate | |
calendars:calendars]; | |
NSArray *events = [[EKEventStore new] eventsMatchingPredicate:predicate]; |
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 Foundation | |
class Event : NSObject, NSCoding { | |
var name : String? | |
var details : String? | |
var date : NSDate? | |
init(name : String, details : String, date : NSDate) { | |
self.name = name |
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 application(application: UIApplication, handleWatchKitExtensionRequest userInfo: [NSObject : AnyObject]?, reply: ([NSObject : AnyObject]?) -> Void) { | |
let message = userInfo?["message"] as! String | |
let event = Event(name: "test", details: "test", date:NSDate()) | |
NSKeyedArchiver.setClassName("Event", forClass: Event.self) | |
NSKeyedArchiver.archivedDataWithRootObject(event) | |
let dictionary = ["event" : event] | |
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
@IBAction func buttonAction() { | |
let dictionary = ["message": "Hi, apple watch here!"] | |
WKInterfaceController.openParentApplication(dictionary) { | |
(replyInfo, error) -> Void in | |
let reply = replyInfo["event"] as! NSData // take our encoded event from dictionary | |
NSKeyedUnarchiver.setClass(Event.self, forClassName: "Event") // We are not using original class anymore, so we have to do it | |
let event = NSKeyedUnarchiver.unarchiveObjectWithData(reply) // decode the event | |
} |
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 application(application: UIApplication, handleWatchKitExtensionRequest userInfo: [NSObject : AnyObject]?, reply: ([NSObject : AnyObject]?) -> Void) { | |
let message = userInfo?["message"] as! String // we can get a message, that we sent from watch | |
let event = Event(name: "test", details: "test", date:NSDate()) // create our Event object | |
NSKeyedArchiver.setClassName("Event", forClass: Event.self) // We are using 'different' classes on watch and iPhone, so we have to do it | |
let archivedEvent = NSKeyedArchiver.archivedDataWithRootObject(event) // archive the Event | |
let dictionary = ["event" : archivedEvent] // creating dictionary with our NSData | |
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
public private(set) lazy var imageView: UIImageView = { | |
let imageView = UIImageView() | |
imageView.layer.cornerRadius = Dimensions.imageSize / 2 | |
imageView.clipsToBounds = true | |
imageView.contentMode = .ScaleAspectFill | |
return imageView | |
}() |