Расширения добавляют новые функциональные возможности к существующему классу, структуре, перечислению или типу протокола.
Синтаксис для расширения:
extension ViewControllerName {
// Put code which you want to
}
/**
If you implement UITableViewDataSource and UITableViewDelegate methods
or you can implement for UIPickerViewDataSource methods and protocol also
*/
extension ViewController: UItableViewDataSource, UITableViewDelegate {
//implement tableview datasource and delegate method
}
/**
Keyboard show/hide
*/
extension ViewController {
/**
Add scrollview functionality to scroll top and you can call
this function from anywhere in the controller.
*/
func scrollToTop() {
}
@objc func keyboardWasShown(notification: NSNotification)
{
var info = notification.userInfo!
let keyboardSize = (info[UIResponder.keyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue.size
let contentInsets : UIEdgeInsets = UIEdgeInsets(top: 0.0, left: 0.0, bottom: keyboardSize!.height+10, right: 0.0)
self.scrolView.contentInset = contentInsets
self.scrolView.scrollIndicatorInsets = contentInsets
var aRect : CGRect = self.view.frame
aRect.size.height -= keyboardSize!.height
if let activeField = self.activeTextField
{
if (!aRect.contains(activeField.frame.origin))
{
self.scrolView.scrollRectToVisible(activeField.frame, animated: true)
}
}
}
// when keyboard hide reduce height of scroll view
@objc func keyboardWillBeHidden(notification: NSNotification){
let contentInsets : UIEdgeInsets = UIEdgeInsets(top: 0.0, left: 0.0,bottom: 0.0, right: 0.0)
self.scrolView.contentInset = contentInsets
self.scrolView.scrollIndicatorInsets = contentInsets
self.view.endEditing(true)
}
}
По общему мнению представителей всех отраслей, переключение задач пагубно. Чем сложнее задачи, тем больше ущерб. Если вы ищете научные аргументы в пользу этого, попробуйте эти:
Все перечисленные выше статьи содержат очень много ссылок и ссылок, если вам интересно узнать больше. Я не уверен, может ли какой-либо из этих источников сделать доступными необработанные данные.
Что касается более легкой и короткой стороны, это не научная тема, но и не блогография:
Joel на программном обеспечении: человеческие переключения задач, продуманные вредный
Кодирование ужаса: многозадачный миф
Две статьи от Kathy Sierra (из блога Создающих Влюбленных Пользователей) на многозадачности. 1, 2
Она не цитирует статьи явно, но действительно перечисляет некоторых авторов, которые могут обеспечить то, что Вы после.
Отличное общее резюме (не ограничиваясь задачами программирования) стоимости переключения задач здесь - резюме написано в терминах, доступных для неспециалистов, но опубликовано на довольно уважаемом сайте (онлайн-сайт Американской психологической ассоциации ) и заканчивается библиографией из десятка хороших ссылок на престижные рецензируемые журналы. Для получения большинства цифр вам придется обратиться к указанным журналам - в резюме цитируются только знаменитые измерения Мейера,
которые даже краткие умственные блоки, созданные переключение между задачами может стоить как почти 40 процентов чьих-либо productive time
That summary is from 2006, and research in the fields has of course continued since. A drier and less accessible, but more recent research survey from earlier this year is here (a site at Michigan State University) -- it quotes and summarizes a dozen of the survey author's works (Erik M. Altmann, associate professor with the Department of Psychology at Michigan State University). All links in this summary are to freely downloadable PDFs, so starting from here may be handier than the study I previously quoted if you don't have access to JSTOR through your library or research institution; however, what you get here is basically a good survey of the work of just one researcher.
Of course, no summary can replace going right to the peer-reviewed scholarly journals and studying (and critically assessing) all the relevant results. It is, however, a work that will take you years, because task-switching costs and human multitasking issues are an extremely popular research field these days -- from the neuroscientists to the behavioral psychologists and management scientists, everybody wants a slice of the action. A Google Scholar search for task-switching costs shows 16,400 results -- many of those are freely accessible even without JSTOR, most all with be with JSTOR or other similar gateways to published research, though probably understanding most of them thoroughly will require a few PhDs in related disciplines (peer-reviewed journals do tend to be that way;-).
BTW, answering the question you ask in your Q's title: way scientifically proven (as solidly as, say, evolution, or global warming, though of course you'll always find deniers for any of those too;-) -- the hot debate and enormous volume of research is about understanding what are the exact numeric parameters of task-switching costs, how they depend on the tasks and on other circumstances, what neurological or other pathways explain what part of them, how to organize to reduce or minimize them, and so forth. Whether the famous "40% productivity loss" estimate is roughly in the ballpark (as I suspect it is) may still be somewhat contentious, but the existence of the effect as a some pretty relevant number (and with enormous economic costs all over the world, once you consider that it applies to every task human beings perform -- permanently raising every human being's productivity by even 10 % would mean a huge jump ahead for the world!-) is essentially beyond doubt.