Skip to content

Instantly share code, notes, and snippets.

View azimin's full-sized avatar
🚀
A new project is coming

Alexander Zimin azimin

🚀
A new project is coming
View GitHub Profile
@azimin
azimin / UIApplicationShortcutItem.swift
Last active October 15, 2016 14:18
UIApplicationShortcutItem creating example
let shortcutExample = UIMutableApplicationShortcutItem(type: "my_app_basic_shortcut", localizedTitle: "Name")
shortcutExample.type = "my_app_basic_shortcut" // identify for your shortcut item (MUST EXIST)
shortcutExample.localizedTitle = "Name" // name of shortcut (MUST EXIST)
shortcutExample.localizedSubtitle = "Info about action" // subtitle of shortcut
shortcutExample.icon = UIApplicationShortcutIcon(type: .update) // inco of shortcut, will be discribed later
shortcutExample.userInfo = ["NoteItem": note as NSSecureCoding] // additional info, must be [String : NSSecureCoding]
// Update the application providing the initial 'dynamic' shortcut items.
application.shortcutItems = [shortcutExample]
@azimin
azimin / HandleUIApplicationShortcutItem.swift
Last active January 19, 2017 00:17
Method that handle UIApplicationShortcutItem and select tab from its info
func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) {
let handled = handleShortcutItem(shortcutItem)
completionHandler(handled)
}
func handleShortcutItem(_ shortcutItem: UIApplicationShortcutItem) -> Bool {
if shortcutItem.type != basicShortcutTypeString {
return false
}
if traitCollection.forceTouchCapability == .available {
registerForPreviewing(with: self, sourceView: view)
}
extension ViewController: UIViewControllerPreviewingDelegate {
func previewingContext(_ previewingContext: UIViewControllerPreviewing, viewControllerForLocation location: CGPoint) -> UIViewController? {
let viewController = UIViewController()
// ...
return viewController
}
func previewingContext(_ previewingContext: UIViewControllerPreviewing, commit viewControllerToCommit: UIViewController) {
// ...
}
func previewingContext(_ previewingContext: UIViewControllerPreviewing, viewControllerForLocation location: CGPoint) -> UIViewController? {
guard let indexPath = collectionView.indexPathForItem(at: location),
let cell = collectionView.cellForItem(at: indexPath) else { return nil }
guard let detailViewController = storyboard?.instantiateViewControllerWithIdentifier("ColorViewController") as? ColorViewController else { return nil }
detailViewController.preferredContentSize = CGSize(width: 300, height: 300)
detailViewController.color = colors[indexPath.row]
previewingContext.sourceRect = cell.frame
func previewingContext(_ previewingContext: UIViewControllerPreviewing, commit viewControllerToCommit: UIViewController) {
show(viewControllerToCommit, sender: nil)
}
@azimin
azimin / Podfile
Created June 30, 2016 10:04
Swift Version Setup in Podfile
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |configuration|
configuration.build_settings['SWIFT_VERSION'] = "2.3"
end
end
end
@azimin
azimin / Podfile
Created June 30, 2016 11:48
Autosign podfile
developer_info = {
"DevelopmentTeam" => "5-------S4",
"DevelopmentTeamName" => "Alexander Zimin"
}
post_install do |installer|
path = installer.pods_project.path
pbxproj_path = path + 'project.pbxproj'
unless File.exist?(pbxproj_path)
# Uncomment this line to define a global platform for your project
# platform :ios, '9.0'
target 'YouApp' do
use_frameworks!
# Pods for YouApp
pod 'SwiftFramework', :branch => 'swift-2.3'
end
@azimin
azimin / prepare-commit-msg
Created November 8, 2016 15:20
prepare-commit-msg that take part of branch name
#!/bin/sh
#
# An example hook script to prepare the commit log message.
# Called by "git commit" with the name of the file that has the
# commit message, followed by the description of the commit
# message's source. The hook's purpose is to edit the commit
# message file. If the hook fails with a non-zero status,
# the commit is aborted.
#