<commit_before>// MIT license. Copyright (c) 2016 SwiftyFORM. All rights reserved.
import UIKit

public enum TableViewSectionPart {
	case none
	case systemDefault
	case titleString(string: String)
	case titleView(view: UIView)
	
	var title: String? {
		switch self {
		case let .titleString(string):
			return string
		default:
			return nil
		}
	}
	
	var view: UIView? {
		switch self {
		case let .titleView(view):
			return view
		default:
			return nil
		}
	}
	
	var height: CGFloat {
		switch self {
		case .none:
			return 0
		case .systemDefault:
			return UITableViewAutomaticDimension
		case let .titleView(view):
			return view.frame.height
		case .titleString(_):
			return UITableViewAutomaticDimension
		}
	}
	
	var estimatedHeight: CGFloat {
		switch self {
		case .none:
			/**
			We don't want any header/footer to be visible. The height should be zero pixels.
			However returning an estimated height smaller than 2 pixels 
			causes UITableView to think that the height is 44 pixels
			Thus the lowest estimated height we can return is 2 pixels
			*/
			return 2
		case .systemDefault:
			return UITableViewAutomaticDimension
		case let .titleView(view):
			return view.frame.height
		case .titleString(_):
			return 44
		}
	}
}<commit_msg>Fixed potential source of crashes. When the estimatedHeightForHeaderInSection() function return too low values, then UITableView.deleteRows() could crash when the row to be deleted was partially outside the screen.<commit_after>// MIT license. Copyright (c) 2016 SwiftyFORM. All rights reserved.
import UIKit

public enum TableViewSectionPart {
	case none
	case systemDefault
	case titleString(string: String)
	case titleView(view: UIView)
	
	var title: String? {
		switch self {
		case let .titleString(string):
			return string
		default:
			return nil
		}
	}
	
	var view: UIView? {
		switch self {
		case let .titleView(view):
			return view
		default:
			return nil
		}
	}
	
	var height: CGFloat {
		switch self {
		case .none:
			return 0
		case .systemDefault:
			return UITableViewAutomaticDimension
		case let .titleView(view):
			return view.frame.height
		case .titleString(_):
			return UITableViewAutomaticDimension
		}
	}
	
	var estimatedHeight: CGFloat {
		switch self {
		case .none:
			/**
			We don't want any header/footer to be visible. The height should be zero pixels.
			However returning an estimated height smaller than 2 pixels 
			causes UITableView to think that the height is 44 pixels
			Thus the lowest estimated height we can return is 2 pixels
			*/
			return 2
		case .systemDefault:
			return UITableViewAutomaticDimension
		case let .titleView(view):
			/**
			Returning too low values can causes expand/collapse to crash.
			The crash happens in UITableView.deleteRows() when tapping collapse.
			Solution is to ensure that the value never drops below 10 pixels.
			*/
			return max(view.frame.height, 10)
		case .titleString(_):
			return 44
		}
	}
}
{'fraction_non_alphanumeric': 0.06689303904923599, 'fraction_numerical': 0.009507640067911714, 'mean_word_length': 3.3259911894273126, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2123015', 'n_tokens_mistral': 1041, 'n_tokens_neox': 852, 'n_words': 335}