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 url = URL(string: "mainAppUrl://")! | |
self.extensionContext?.open(url, completionHandler: { (success) in | |
if (!success) { | |
print("error: failed to open app from Today Extension") | |
} | |
}) |
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
class PersistentContainer: NSPersistentContainer{ | |
override class func defaultDirectoryURL() -> URL{ | |
return FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "group.sharingForTodayExtension")! | |
} | |
override init(name: String, managedObjectModel model: NSManagedObjectModel) { | |
super.init(name: name, managedObjectModel: model) | |
} | |
} |
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 sharedDefaults = UserDefaults.init(suiteName: "group.sharingForTodayExtension") | |
let text = sharedDefaults?.value(forKey: "customKey") |
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 sharedDefaults = UserDefaults(suiteName: "group.sharingForTodayExtension") | |
sharedDefaults?.setValue("Stfalcon.com today extension tutorial", forKey: "customKey") |
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 widgetActiveDisplayModeDidChange(_ activeDisplayMode: NCWidgetDisplayMode, withMaximumSize maxSize: CGSize) { | |
animateTextLabels() | |
if activeDisplayMode == .compact { | |
self.preferredContentSize = maxSize | |
} else if activeDisplayMode == .expanded { | |
self.preferredContentSize = CGSize(width: maxSize.width, height: 150) | |
} | |
} |
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 animateTextLabels() { | |
let isExpandedMode = self.extensionContext?.widgetActiveDisplayMode == .expanded | |
let scaleText:CGFloat = isExpandedMode ? 3 : 0.3 | |
UIView.animate(withDuration: 0.3, delay: 0, options: [.curveEaseOut], animations: { | |
self.textLabel.transform = .init(scaleX: scaleText, y: scaleText) | |
self.dateLabel.transform = isExpandedMode ? .init(translationX: 0, y: 20) : .identity | |
}) { (finished) in | |
UIView.animate(withDuration: 0.3, animations: { | |
self.textLabel.transform = .identity | |
}) |
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
@IBOutlet weak var textLabel:UILabel! | |
@IBOutlet weak var dateLabel:UILabel! |
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 widgetActiveDisplayModeDidChange(_ activeDisplayMode: NCWidgetDisplayMode, withMaximumSize maxSize: CGSize) { | |
if activeDisplayMode == .compact { | |
self.preferredContentSize = maxSize | |
} else if activeDisplayMode == .expanded { | |
self.preferredContentSize = CGSize(width: maxSize.width, height: 150) | |
} | |
} |
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
override func viewDidLoad() { | |
super.viewDidLoad() | |
self.extensionContext?.widgetLargestAvailableDisplayMode = .expanded | |
} |
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
// Find all rabbits in locations which | |
// end on: shire, field, wood | |
// starts on: yellow, green | |
// and are not case sensitive | |
// e.g. Blackshire, Greenfield, Sherwood, SHERWOOD, wood, Yellowstone | |
$locationsRegExp = '/\b(yellow|green)\w*|\w*(shire|field|wood)\b/i'; | |
$rabbits = $search->findRabbitsInLocations(locationsRegExp); |
NewerOlder