I'm getting crashes, sometimes when I try to remove all arrangedSubviews in a UIStackView. If I use only UILabel with no styling, it works fine.
I have this function to remove the children:
extension UIStackView {
func removeAllArrangedSubviews() {
for child in self.arrangedSubviews {
self.removeArrangedSubview(child)
child.removeFromSuperview()
}
}
}
I setup the UILabel like so:
public class func setToLabel(label:UILabel) {
label.setFontRegular(10)
label.setFontColor(BaseStyleColors.c4)
}
I have this to setup the fonts:
public class FontHelpers {
public class func systemFontWithMonospacedNumbers(currentFont:UIFont) -> UIFont {
let features = [
[
UIFontFeatureTypeIdentifierKey: kNumberSpacingType,
UIFontFeatureSelectorIdentifierKey: kMonospacedNumbersSelector
]
]
let fontDescriptor = currentFont.fontDescriptor().fontDescriptorByAddingAttributes(
[UIFontDescriptorFeatureSettingsAttribute: features]
)
return UIFont(descriptor: fontDescriptor, size: currentFont.pointSize)
}
public static var bodyStyleFont = UIFont.preferredFontForTextStyle(UIFontTextStyleBody)
public static var headlineStyleFont = UIFont.preferredFontForTextStyle(UIFontTextStyleHeadline)
public class func useBodyFontWithSize(size:CGFloat) -> UIFont {
return UIFont(descriptor: self.bodyStyleFont.fontDescriptor(), size: size)
}
public class func useHeadlineFontWithSize(size:CGFloat) -> UIFont {
return UIFont(descriptor: self.headlineStyleFont.fontDescriptor(), size: size)
}
public class func useSystemFontMediumWithSize(size:CGFloat) -> UIFont {
return UIFont(name: ".SFUIText-Medium", size: size) ?? self.useBodyFontWithSize(size)
}
public class func useSystemFontSemiBoldWithSize(size:CGFloat) -> UIFont {
return UIFont(name: ".SFUIText-SemiBold", size: size) ?? self.useBodyFontWithSize(size)
}
}
Label extension
extension UILabel {
func setFontColor(color:UIColor) {
self.textColor = color
}
func setFontDisplayMedium(size:CGFloat) {
self.font = FontHelpers.systemFontWithMonospacedNumbers(FontHelpers.useSystemFontMediumWithSize(size))
}
func setFontMedium(size:CGFloat) {
self.font = FontHelpers.useSystemFontMediumWithSize(size)
}
func setFontRegular(size:CGFloat) {
self.font = FontHelpers.useBodyFontWithSize(size)
}
func setFontSemiBold(size:CGFloat) {
self.font = FontHelpers.useSystemFontSemiBoldWithSize(size)
}
}
In console I get this error:
Auto layout internal error. Cannot find an outgoing row head for incoming head during optimization of variable with near-zero coefficient, which should never happen.
2016-04-04 08:09:59.877 MyApp[49788:4979069] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '{objective 0x7f9fe3fc9350: <250:289.293> + <250:-3.58537>*0x7f9fe141ccf0:UISV-canvas-connection.marker{id: 1121} + <250:2.58537>*0x7f9fe141d080:UISV-alignment.marker{id: 1123} + <998:-0.999999, 250:2.58537>*0x7f9fe1439130:UISV-alignment.marker{id: 1094} + <998:0.999999, 250:-2.58537>*0x7f9fe1439250:UISV-alignment.marker{id: 1095} + <750:1, 250:1>*0x7f9fe14395e0.negError{id: 1099} + <750:1, 250:1>*0x7f9fe1439750.negError{id: 1126} + <750:1, 250:1>*0x7f9fe1439a10.negError{id: 1103} + <750:1, 250:1>*0x7f9fe1439a70.negError{id: 1105} + <998:1, 250:-0.585366>*0x7f9fe1439e10:UISV-canvas-connection.marker{id: 1106} + <998:-1, 250:0.585366>*0x7f9fe143a010:UISV-canvas-connection.marker{id: 1113} + <998:-1, 250:0.585366>*0x7f9fe143a6f0:UISV-spacing.marker{id: 1115} + <999:1, 998:1, 250:-1.58537>*0x7f9fe143a860:UISV-fill-proportionally.negError{id: 1117} + <999:1, 998:-1, 250:1.58537>*0x7f9fe143a860:UISV-fill-proportionally.posErrorMarker{id: 1116} + <998:2>*0x7f9fe143abd0:UISV-fill-proportionally.negError{id: 1119} + <250:3.58537>*0x7f9fe143ae70:UISV-canvas-connection.marker{id: 1120} + <750:1, 250:1>*0x7f9fe1446d20.negError{id: 1010} + <750:1, 250:1>*0x7f9fe1449b30.negError{id: 981} + <998:2>*0x7f9fe145c160:UISV-fill-proportionally.negError{id: 1003} + <998:-1, 250:-0.585365>*0x7f9fe1460980:UISV-canvas-connection.marker{id: 1019} + <998:1, 250:0.585365>*0x7f9fe1460b60:UISV-canvas-connection.marker{id: 1026} + <999:1, 998:-1, 250:-1.58537>*0x7f9fe1460d00:UISV-fill-proportionally.negError{id: 1030} + <999:1, 998:1, 250:1.58537>*0x7f9fe1460d00:UISV-fill-proportionally.posErrorMarker{id: 1029} + <998:-1, 250:-0.585366>*0x7f9fe1461610:UISV-canvas-connection.marker{id: 1048} + <998:1, 250:0.585366>*0x7f9fe1461810:UISV-canvas-connection.marker{id: 1055} + <750:1, 250:1>*0x7f9fe14618b0.negError{id: 1018} + <750:1, 250:1>*0x7f9fe1463960.negError{id: 1016} + <998:1, 250:0.585365>*0x7f9fe1464720:UISV-spacing.marker{id: 1028} + <999:1, 998:1>*0x7f9fe1464cd0:UISV-fill-proportionally.negError{id: 1001} + <999:1, 998:-1>*0x7f9fe1464cd0:UISV-fill-proportionally.posErrorMarker{id: 1000} + <750:1, 250:1>*0x7f9fe1468c90.negError{id: 1012} + <750:1, 250:1>*0x7f9fe1468e00.negError{id: 1039} + <750:1, 250:1>*0x7f9fe1469250.negError{id: 987} + <750:1, 250:1>*0x7f9fe14692b0.negError{id: 989} + <998:-1>*0x7f9fe1469960:UISV-alignment.marker{id: 1007} + <998:1>*0x7f9fe1469a80:UISV-alignment.marker{id: 1008} + <998:-1>*0x7f9fe146b870:UISV-canvas-connection.marker{id: 1004} + <998:1>*0x7f9fe146b960:UISV-canvas-connection.marker{id: 1005} + <999:-2.42144e-07, 998:-1, 250:-2>*0x7f9fe146d360:UISV-spacing.marker{id: 999} + <998:1, 250:0.585366>*0x7f9fe146eeb0:UISV-spacing.marker{id: 1057} + <999:1, 998:-1, 250:-1.58537>*0x7f9fe146efd0:UISV-fill-proportionally.negError{id: 1059} + <999:1, 998:1, 250:1.58537>*0x7f9fe146efd0:UISV-fill-proportionally.posErrorMarker{id: 1058} + <250:-2.58537>*0x7f9fe14723c0:UISV-alignment.marker{id: 1066} + <999:-2.42144e-07, 998:-1, 250:-2>*0x7f9fe1472ad0:UISV-canvas-connection.marker{id: 997} + <999:1, 998:1, 250:-1.58537>*0x7f9fe14752a0:UISV-fill-proportionally.negError{id: 1088} + <999:1, 998:-1, 250:1.58537>*0x7f9fe14752a0:UISV-fill-proportionally.posErrorMarker{id: 1087} + <998:2>*0x7f9fe1475610:UISV-fill-proportionally.negError{id: 1090} + <998:-0.999999, 250:3.58537>*0x7f9fe14758b0:UISV-canvas-connection.marker{id: 1091} + <998:0.999999, 250:-3.58537>*0x7f9fe14759a0:UISV-canvas-connection.marker{id: 1092} + <250:3.58537>*0x7f9fe14764e0:UISV-canvas-connection.marker{id: 1033} + <250:-3.58537>*0x7f9fe14765d0:UISV-canvas-connection.marker{id: 1034} + <250:2.58537>*0x7f9fe1476b90:UISV-alignment.marker{id: 1036} + <250:-2.58537>*0x7f9fe1476cb0:UISV-alignment.marker{id: 1037} + <750:1, 250:1>*0x7f9fe1478bf0.negError{id: 983} + <250:-2.62021>*0x7f9fe14798a0:UISV-spacing.marker{id: 1163} + <999:2.42144e-07, 998:1, 250:2>*0x7f9fe147a220:UISV-canvas-connection.marker{id: 990} + <998:2>*0x7f9fe147c1b0:UISV-fill-proportionally.posErrorMarker{id: 1031} + <750:1, 250:1>*0x7f9fe147ccf0.negError{id: 1041} + <750:1, 250:1>*0x7f9fe147ce60.negError{id: 1068} + <750:1, 250:1>*0x7f9fe147d120.negError{id: 1045} + <750:1, 250:1>*0x7f9fe147d180.negError{id: 1047} + <998:2>*0x7f9fe1484350:UISV-fill-proportionally.posErrorMarker{id: 1060} + <250:3.58537>*0x7f9fe14845f0:UISV-canvas-connection.marker{id: 1062} + <250:-3.58537>*0x7f9fe14846e0:UISV-canvas-connection.marker{id: 1063} + <250:2.58537>*0x7f9fe14849f0:UISV-alignment.marker{id: 1065} + <750:1, 250:1>*0x7f9fe1486c40.negError{id: 1070} + <750:1, 250:1>*0x7f9fe1486db0.negError{id: 1097} + <750:1, 250:1>*0x7f9fe1487070.negError{id: 1074} + <750:1, 250:1>*0x7f9fe14870d0.negError{id: 1076} + <998:1, 250:-0.585366>*0x7f9fe14874a0:UISV-canvas-connection.marker{id: 1077} + <998:-1, 250:0.585366>*0x7f9fe14876a0:UISV-canvas-connection.marker{id: 1084} + <998:-1, 250:0.585366>*0x7f9fe1487890:UISV-spacing.marker{id: 1086} + <250:-2.58537>*0x7f9fe14889b0:UISV-alignment.marker{id: 1124} + <750:1, 250:1>*0x7f9fe1488d40.negError{id: 1128} + <250:2.62021>*0x7f9fe1488ee0:UISV-canvas-connection.marker{id: 1154} + <750:1, 250:1>*0x7f9fe1489170.negError{id: 1132} + <750:1, 250:1>*0x7f9fe14891d0.negError{id: 1134} + <999:2.42144e-07, 998:1, 250:2>*0x7f9fe1489570:UISV-canvas-connection.marker{id: 1135} + <999:-2.42144e-07, 998:-1, 250:-2>*0x7f9fe1489770:UISV-canvas-connection.marker{id: 1142} + <999:-2.42144e-07, 998:-1, 250:-2>*0x7f9fe1489e50:UISV-spacing.marker{id: 1144} + <999:1, 998:1>*0x7f9fe1489fc0:UISV-fill-proportionally.negError{id: 1146} + <999:1, 998:-1>*0x7f9fe1489fc0:UISV-fill-proportionally.posErrorMarker{id: 1145} + <998:2>*0x7f9fe148a330:UISV-fill-proportionally.negError{id: 1148} + <998:-1>*0x7f9fe148a5d0:UISV-canvas-connection.marker{id: 1149} + <998:1>*0x7f9fe148a6c0:UISV-canvas-connection.marker{id: 1150} + <998:-1>*0x7f9fe148ac80:UISV-alignment.marker{id: 1152} + <998:1>*0x7f9fe148ada0:UISV-alignment.marker{id: 1153} + <250:-2.62021>*0x7f9fe148b200:UISV-spacing.marker{id: 1156} + <250:-2.62021>*0x7f9fe148b2c0:UISV-canvas-connection.marker{id: 1155} + <250:-2.62021>*0x7f9fe148b3e0:UISV-spacing.marker{id: 1157} + <250:-2.62021>*0x7f9fe148bbb0:UISV-spacing.marker{id: 1159} + <250:0.965157>*0x7f9fe148c4d0:UISV-fill-equally.marker{id: 1160} + <250:0.965157>*0x7f9fe148c850:UISV-fill-equally.marker{id: 1162} + <998:-0.999999, 250:0.965157>*0x7f9fe148d220:UISV-fill-equally.marker{id: 1164} + <250:-0.620209>*0x7f9fe148d270:UISV-fill-equally.marker{id: 1158} + <250:-2.62021>*0x7f9fe148d450:UISV-spacing.marker{id: 1161} + <250:-2.62021>*0x7f9fe148ff30:UISV-spacing.marker{id: 1165} + <250:2.62021>*0x7f9fe1520c60.marker{id: 919} + <250:-1.26154>*0x7f9fe15eeda0.marker{id: 917} + <250:-1.26154>*0x7f9fe50bb470:UISV-canvas-connection.marker{id: 1174} + <999:2>*0x7f9fe50c51e0.negError{id: 922} + <999:2>*0x7f9fe50cefe0.negError{id: 925} + <998:1>*0x7f9fe5113050.marker{id: 899} + <250:-1.58537>*0x7f9fe5130060.marker{id: 902} + <250:-1.58537>*0x7f9fe513af60.marker{id: 905} + <998:0.999999, 250:-1.58537>*0x7f9fe51502a0.marker{id: 908} + <250:-1.58537>*0x7f9fe5164440.marker{id: 911} + <250:-0.620209>*0x7f9fe516ba50:UISV-fill-equally.marker{id: 1171} + <998:1>*0x7f9fe517b4b0.marker{id: 914} + <250:0.965157>*0x7f9fe53e18a0:UISV-fill-equally.marker{id: 1168} + <250:0.00905983>*UIStackView:0x7f9fe1526830.Height{id: 966} + <999:0.00277778>*_UILayoutGuide:0x7f9fe53be860.Width{id: 923} + <999:0.00277778>*_UILayoutGuide:0x7f9fe53be9f0.Width{id: 926}}: internal error. Setting empty vector for variable MyApp.StyledLabelT1:0x7f9fe53d8120'4'.Height{id: 898}.'
Auto layout internal error. Cannot find an outgoing row head for incoming head during optimization of variable with near-zero coefficient, which should never happen.
Call stack:
*** First throw call stack:
(
0 CoreFoundation 0x000000010e136d85 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000110dcedeb objc_exception_throw + 48
2 CoreFoundation 0x000000010e136cbd +[NSException raise:format:] + 205
3 Foundation 0x000000010efa7acc -[NSISObjectiveLinearExpression setPriorityVector:forKnownAbsentVariable:] + 76
4 Foundation 0x000000010f14ac44 __128-[NSISObjectiveLinearExpression replaceVariable:withExpression:processVariableNewToReceiver:processVariableDroppedFromReceiver:]_block_invoke + 297
5 Foundation 0x000000010efa46bf -[NSISLinearExpression enumerateVariablesAndCoefficients:] + 350
6 Foundation 0x000000010f14ab04 -[NSISObjectiveLinearExpression replaceVariable:withExpression:processVariableNewToReceiver:processVariableDroppedFromReceiver:] + 369
7 Foundation 0x000000010efa57ee -[NSISEngine substituteOutAllOccurencesOfBodyVar:withExpression:] + 633
8 Foundation 0x000000010efa8789 -[NSISEngine pivotToMakeBodyVar:newHeadOfRowWithHead:andDropRow:] + 330
9 Foundation 0x000000010efb2c21 -[NSISEngine removeConstraintWithMarker:] + 707
10 Foundation 0x000000010ef99899 -[NSLayoutConstraint _removeFromEngine:] + 229
11 UIKit 0x0000000110139d81 -[UIView(UIConstraintBasedLayout) _layoutEngine_willRemoveLayoutConstraint:] + 173
12 UIKit 0x000000011013a6b6 -[UIView(UIConstraintBasedLayout) nsli_removeConstraint:] + 114
13 UIKit 0x000000011013a62d -[UIView(UIConstraintBasedLayout) _removeConstraint:] + 301
14 UIKit 0x000000011014adde _UIViewRemoveConstraintsMadeDanglyByChangingSuperview + 1028
15 UIKit 0x000000010f8fc504 __45-[UIView(Hierarchy) _postMovedFromSuperview:]_block_invoke + 61
16 UIKit 0x000000010f8fc461 -[UIView(Hierarchy) _postMovedFromSuperview:] + 544
17 UIKit 0x000000010f8fa489 __UIViewWasRemovedFromSuperview + 213
18 UIKit 0x000000010f8f9fbf -[UIView(Hierarchy) removeFromSuperview] + 474
If I modify the method to also clear any sub UIStackViews, I 100% of the times get a crash, like so:
extension UIStackView {
func removeAllArrangedSubviews() {
for child in self.arrangedSubviews {
if let childStackView = child as? UIStackView {
childStackView.removeAllArrangedSubviews()
}
self.removeArrangedSubview(child)
child.removeFromSuperview()
}
}
}
Versions: I'm running Xcode 7.3 and iOS 9.3.
Related
I am getting a crash reported in crashlytics about partial apply in closure. I have tried other answers that mainly focus on using [weak self] but that didn't help. However, i am not getting a crash on my device.
According to the report the crash is somewhere in the function where i show my dropDown here is the code
func showDropDown(_ names: [String], forResult result: SearchPatientResultResponnse) {
guard let vc = viewController
else { return }
self.searchedPatientNames = result.data?.patientSearchSuggestions
Helpers.showSearchDropdown(anchorView: vc.searchBar.searchTextField, dataSource: names, scrollToTop: true, completion: { [weak self] (i, item) in
guard let self = self else {
return
}
vc.searchBar.text = item
vc.dismissKeyboard()
self.selectedSearchPatient = self.searchedPatientNames?[i]
if let d = self.searchedPatientNames?[i].dob {
vc.dobTF.text = DateTimeFormatters.userUIDateFormatterInUTC.string(from: d)
}
self.search(self.selectedSearchFilter)
}, fetchPaginationData: { [weak self] in
guard let self = self, !self.isNameSearchLastPage, self.page != -1 else {
return
}
vc.searchBar.isLoadingWithoutSearchIcon = true
self.fetchPatientNameNextPage()
}, cancel: { [weak self] in
self?.resetPaginationParams()
})
}
This is the function from where i am calling this showDropDown function
func getQueryPatientResponse() {
guard let vc = viewController else {
return
}
SocketIOManager.shared.queryResponseForPatient = { [weak self] result in
var names: [String] = []
self?.isNameSearchLastPage = result.data?.isLastPage ?? true
self?.page = result.data?.pageNumber ?? -1
for data in result.data?.patientSearchSuggestions ?? [] {
var name = ""
if !data.middleName.isEmpty {
name = data.firstName + " " + data.middleName + " " + data.lastName
} else {
name = data.firstName + " " + (data.lastName)
}
names.append(name)
}
vc.searchBar.isLoadingWithoutSearchIcon = false
self?.page == 1 ? self?.showDropDown(names, forResult: result) : self?.updateDropDown(names, forResult: result)
}
}
This is the crash report from crashlytics:-
Crashed: com.apple.main-thread
0 Ovada CM - PT 0x639b0 closure #1 in VisitStatusViewModel.showDropDown(_:forResult:)
+ 4340890032 (<compiler-generated>:4340890032)
1 Ovada CM - PT 0x3f328 partial apply for closure #1 in static Helpers.showSearchDropdown(anchorView:dataSource:scrollToTop:completion:fetchPaginationData:cancel:)
+ 121 (Helpers.swift:121)
2 Ovada CM - PT 0x15604c DropDown.tableView(_:didSelectRowAt:)
+ 4341882956 (<compiler-generated>:4341882956)
3 Ovada CM - PT 0x156548 #objc DropDown.tableView(_:didSelectRowAt:)
+ 4341884232 (<compiler-generated>:4341884232)
4 UIKitCore 0xfe36d0 -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:isCellMultiSelect:deselectPrevious:]
+ 1640
5 UIKitCore 0xfe3050 -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:]
+ 112
6 UIKitCore 0xfe394c -[UITableView _userSelectRowAtPendingSelectionIndexPath:]
+ 316
7 UIKitCore 0x30c240 -[_UIAfterCACommitBlock run] + 64
8 UIKitCore 0x227770 -[_UIAfterCACommitQueue flush] + 200
9 UIKitCore 0x155eb0 _runAfterCACommitDeferredBlocks + 640
10 UIKitCore 0x15657c _cleanUpAfterCAFlushAndRunDeferredBlocks + 128
11 UIKitCore 0x156748 _afterCACommitHandler + 56
12 CoreFoundation 0x3e83c _CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION_ + 32
13 CoreFoundation 0xfa74 __CFRunLoopDoObservers + 616
14 CoreFoundation 0xaffc __CFRunLoopRun + 1012
15 CoreFoundation 0x1e250 CFRunLoopRunSpecific + 572
16 GraphicsServices 0x1988 GSEventRunModal + 160
17 UIKitCore 0x4e5a94 -[UIApplication _run] + 1080
18 UIKitCore 0x27efd4 UIApplicationMain + 336
19 Ovada CM - PT 0x6070 main + 14 (AppDelegate.swift:14)
20 ??? 0x1029dc4d0 (Missing)
I have a set of linear constraints defined on a set of real parameters. The aim is to find a solution of parameters that satisfies maximum number of these constraints. I use the Optimizer in z3 but it is really slow. The number of constraints is 100 and the number of parameters is 9, which is not a large number. I use the following code:
from z3 import *
s = Optimize()
W = RealVector('w', 9)
s.add(And([And(w >= -100, w <= 100) for w in W]))
**Add soft constraints from a text file
out = s.check()
Following is a sample of the soft constraints, each with weight 1, that are added to the problem:
w__0 + 7*w__1 + 181*w__2 + 84*w__3 + 21*w__4 + 192*w__5 + 36*w__6 + 59*w__7 + 51*w__8 > 0
w__0 + 2*w__1 + 127*w__2 + 58*w__3 + 24*w__4 + 275*w__5 + 28*w__6 + 160*w__7 + 25*w__8 < 0
w__0 + 11*w__1 + 138*w__2 + 76*w__3 + 0*w__4 + 0*w__5 + 33*w__6 + 42*w__7 + 35*w__8 < 0
w__0 + 2*w__1 + 81*w__2 + 60*w__3 + 22*w__4 + 0*w__5 + 28*w__6 + 29*w__7 + 25*w__8 < 0
w__0 + 0*w__1 + 84*w__2 + 82*w__3 + 31*w__4 + 125*w__5 + 38*w__6 + 23*w__7 + 23*w__8 < 0
w__0 + 9*w__1 + 140*w__2 + 94*w__3 + 0*w__4 + 0*w__5 + 33*w__6 + 73*w__7 + 45*w__8 > 0
w__0 + 8*w__1 + 197*w__2 + 74*w__3 + 0*w__4 + 0*w__5 + 26*w__6 + 119*w__7 + 39*w__8 > 0
w__0 + 8*w__1 + 120*w__2 + 0*w__3 + 0*w__4 + 0*w__5 + 30*w__6 + 18*w__7 + 38*w__8 > 0
w__0 + 7*w__1 + 161*w__2 + 86*w__3 + 0*w__4 + 0*w__5 + 30*w__6 + 17*w__7 + 47*w__8 > 0
w__0 + 4*w__1 + 120*w__2 + 68*w__3 + 0*w__4 + 0*w__5 + 30*w__6 + 71*w__7 + 34*w__8 < 0
w__0 + 7*w__1 + 187*w__2 + 50*w__3 + 33*w__4 + 392*w__5 + 34*w__6 + 83*w__7 + 34*w__8 > 0
w__0 + 2*w__1 + 87*w__2 + 0*w__3 + 23*w__4 + 0*w__5 + 29*w__6 + 77*w__7 + 25*w__8 < 0
w__0 + 1*w__1 + 97*w__2 + 68*w__3 + 21*w__4 + 0*w__5 + 27*w__6 + 110*w__7 + 22*w__8 < 0
w__0 + 4*w__1 + 123*w__2 + 80*w__3 + 15*w__4 + 176*w__5 + 32*w__6 + 44*w__7 + 34*w__8 < 0
w__0 + 6*w__1 + 195*w__2 + 70*w__3 + 0*w__4 + 0*w__5 + 31*w__6 + 33*w__7 + 31*w__8 > 0
w__0 + 0*w__1 + 101*w__2 + 64*w__3 + 17*w__4 + 0*w__5 + 21*w__6 + 25*w__7 + 21*w__8 < 0
w__0 + 12*w__1 + 92*w__2 + 62*w__3 + 7*w__4 + 258*w__5 + 28*w__6 + 93*w__7 + 44*w__8 > 0
w__0 + 1*w__1 + 88*w__2 + 62*w__3 + 24*w__4 + 44*w__5 + 30*w__6 + 42*w__7 + 23*w__8 < 0
I know that the performance of the solution will depend on the nature of the problem but with 100 such constraints the computations go on forever. Is there any additional option that I can use to make this faster?
I also implemented the fu-malik algorithm myself by extracting the core, even with that it's really slow.
I am getting an exception when I filter and try to delete records from Realm DB. It appears that the records are being deleted. The do / catch however is not responding as I expected. What am I doing wrong?
func deleteRecords (module: String, version:String, workorder: String) {
let realm = try! Realm()
let predicate = NSPredicate(format: "module = %# && version = %# && workorder = %#" , module, version, workorder)
let results = realm.objects(NewRecord.self).filter(predicate)
print("FILTERED: \(results.count) \(results)")
do {
try? realm.write {
for result in results {
print("DELETING: \(result)")
realm.delete(result)
}
}
} catch {
// Catch anything that the above catches didn't catch
print("ERROR THROWN DELETONG")
}
}
The output looks like so:
FILTERED: 2 Results<NewRecord> <0x7f9cb1d27950> (
[0] NewRecord {
id = eaAerator008quantityWRK-000001;
module = eaAerator;
workorder = WRK-000001;
version = 008;
field = quantity;
measure = None;
valueString = 200;
valueData = < — 0 total bytes>;
diStatus = INSTALLED;
},
[1] NewRecord {
id = eaAerator008installedQuantityWRK-000001;
module = eaAerator;
workorder = WRK-000001;
version = 008;
field = installedQuantity;
measure = None;
valueString = 150;
valueData = < — 0 total bytes>;
diStatus = INSTALLED;
}
)
DELETING: NewRecord {
id = eaAerator008quantityWRK-000001;
module = eaAerator;
workorder = WRK-000001;
version = 008;
field = quantity;
measure = None;
valueString = 200;
valueData = < — 0 total bytes>;
diStatus = INSTALLED;
}
DELETING: NewRecord {
id = eaAerator008installedQuantityWRK-000001;
module = eaAerator;
workorder = WRK-000001;
version = 008;
field = installedQuantity;
measure = None;
valueString = 150;
valueData = < — 0 total bytes>;
diStatus = INSTALLED;
}
2017-08-13 23:05:07.982 DSMTracker[925:147376108] *** Terminating app due to uncaught exception 'RLMException', reason: 'Object has been deleted or invalidated.'
*** First throw call stack:
(
0 CoreFoundation 0x0000000107bbab0b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x0000000106d03141 objc_exception_throw + 48
2 Realm 0x00000001055eccf3 _ZL17RLMVerifyAttachedP13RLMObjectBase + 83
3 Realm 0x00000001055ee94c _ZN12_GLOBAL__N_18getBoxedIN5realm10StringDataEEEP11objc_objectP13RLMObjectBasem + 28
4 Realm 0x00000001055ee927 ___ZN12_GLOBAL__N_115makeBoxedGetterIN5realm10StringDataEEEP11objc_objectm_block_invoke + 39
5 DSMTracker 0x00000001044bdfb9 _TFC10DSMTracker23DirectInstallController9tableViewfTCSo11UITableView6commitOSC27UITableViewCellEditingStyle8forRowAtV10Foundation9IndexPath_T_ + 841
6 DSMTracker 0x00000001044be0af _TToFC10DSMTracker23DirectInstallController9tableViewfTCSo11UITableView6commitOSC27UITableViewCellEditingStyle8forRowAtV10Foundation9IndexPath_T_ + 95
7 UIKit 0x000000010942ec8c -[UITableView _animateDeletionOfRowWithCell:] + 172
8 UIKit 0x0000000109404289 __52-[UITableView _swipeActionButtonsForRowAtIndexPath:]_block_invoke + 84
9 UIKit 0x0000000109430334 -[UITableView _actionButton:pushedInCell:] + 212
10 UIKit 0x0000000109690d75 -[UITableViewCell _actionButtonPushed:] + 82
11 UIKit 0x00000001092c1d22 -[UIApplication sendAction:to:from:forEvent:] + 83
12 UIKit 0x000000010944625c -[UIControl sendAction:to:forEvent:] + 67
13 UIKit 0x0000000109446577 -[UIControl _sendActionsForEvents:withEvent:] + 450
14 UIKit 0x00000001094454b2 -[UIControl touchesEnded:withEvent:] + 618
15 UIKit 0x00000001097eaea9 _UIGestureEnvironmentSortAndSendDelayedTouches + 5553
16 UIKit 0x00000001097e5ec0 _UIGestureEnvironmentUpdate + 1409
17 UIKit 0x00000001097e58f3 -[UIGestureEnvironment _deliverEvent:toGestureRecognizers:usingBlock:] + 484
18 UIKit 0x00000001097e4aba -[UIGestureEnvironment _updateGesturesForEvent:window:] + 274
19 UIKit 0x0000000109330b9a -[UIWindow sendEvent:] + 4092
20 UIKit 0x00000001092dd7b0 -[UIApplication sendEvent:] + 352
21 UIKit 0x0000000109ac0adc __dispatchPreprocessedEventFromEventQueue + 2926
22 UIKit 0x0000000109ab8a3a __handleEventQueue + 1122
23 CoreFoundation 0x0000000107b60c01 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
24 CoreFoundation 0x0000000107b460cf __CFRunLoopDoSources0 + 527
25 CoreFoundation 0x0000000107b455ff __CFRunLoopRun + 911
26 CoreFoundation 0x0000000107b45016 CFRunLoopRunSpecific + 406
27 GraphicsServices 0x0000000110337a24 GSEventRunModal + 62
28 UIKit 0x00000001092c00d4 UIApplicationMain + 159
29 DSMTracker 0x00000001048cad27 main + 55
30 libdyld.dylib 0x000000010ca6d65d start + 1
31 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
I'm new to erlang and programming in general.
I want to create a "Grid" of cells, where a cell is presented as:
+ +
+ +
What I know is the width and the height of the Grid.
So, for example, a 3x3 Grid is represented as:
+ + + +
+ + + +
+ + + +
+ + + +
print_grid(Height,Width) ->
and than some code here.
Can someone maybe give me a tip on how to solve this?
For this issue, you may use this function
grid(_,0)->ok;
grid(W,H)->
io:format(string:copies("+ ",W-1)++"+~n~n"),
grid(W,H-1).
output:
sol:grid(6,3).
+ + + + + +
+ + + + + +
+ + + + + +
15> sol:grid(3,3).
+ + +
+ + +
+ + +
I doubt that you do not need other feature like adding some characters in the cells, but you should be able to modify this:
4> Pgrid= fun(W,H) -> L = lists:foldl(fun(_,Acc) -> "+ " ++ Acc end,"~n~n",lists:seq(1,W+1)),
4> G = lists:foldl(fun(_,Acc)-> L ++ Acc end,[],lists:seq(1,H+1)),
4> io:format(G)
4> end.
#Fun<erl_eval.12.54118792>
5> Pgrid(6,3).
+ + + + + + +
+ + + + + + +
+ + + + + + +
+ + + + + + +
ok
6>
I'm building a Xamarin.iOS app, I have a UITableView with a custom UITableViewCell, when I add data from server to the table or if I begin to scroll up and down fast, the app crashes and give me this error log:
Native stacktrace:
>0 CardReader_iOS 0x003b5ed5 mono_handle_native_sigsegv + 260
>1 CardReader_iOS 0x003befad mono_sigsegv_signal_handler + 176
>2 libsystem_platform.dylib 0x3a600063 _sigtramp + 42
>3 CardReader_iOS 0x000d0798
CardReader_iOS_ICTableContactSource_GetCell_MonoTouch_UIKit_UITableView_MonoTouch_Foundation_NSIndexPath + 164
>4 CardReader_iOS 0x002740d0
wrapper_runtime_invoke_object_runtime_invoke_dynamic_intptr_intptr_intptr_intptr + 200
>5 CardReader_iOS 0x003c1087 mono_jit_runtime_invoke + 1134
>6 CardReader_iOS 0x003fbd2d mono_runtime_invoke + 88
>7 CardReader_iOS 0x003914af
native_to_managed_trampoline_CardReader_iOS_ICTableContactSource_GetCell + 402
8 UIKit 0x3256da5b + 410
>9 UIKit 0x32515e7d <redacted> + 1804
>10 UIKit 0x32515699 <redacted> + 184
>11 UIKit 0x3243bda3 <redacted> + 346
>12 QuartzCore 0x320c2c6b <redacted> + 142
>13 QuartzCore 0x320be47b <redacted> + 350
>14 QuartzCore 0x320be30d <redacted> + 16
>15 QuartzCore 0x320bdd1f <redacted> + 230
>16 QuartzCore 0x320bdb2f <redacted> + 314
>17 QuartzCore 0x32112825 <redacted> + 516
>18 IOMobileFramebuffer 0x34d0876d <redacted> + 104
>19 IOKit 0x309aaa75 IODispatchCalloutFromCFMessage + 248
>20 CoreFoundation 0x2fc88e21 <redacted> + 136
>21 CoreFoundation 0x2fc939df <redacted> + 34
>22 CoreFoundation 0x2fc9397b <redacted> + 346
>23 CoreFoundation 0x2fc9214f <redacted> + 1398
>24 CoreFoundation 0x2fbfcc27 CFRunLoopRunSpecific + 522
>25 CoreFoundation 0x2fbfca0b CFRunLoopRunInMode + 106
>26 GraphicsServices 0x348ec283 GSEventRunModal + 138
>27 UIKit 0x324a0049 UIApplicationMain + 1136
>28 CardReader_iOS 0x00166e40
wrapper_managed_to_native_MonoTouch_UIKit_UIApplication_UIApplicationMain_int_string___intptr_intptr + 272
29 CardReader_iOS 0x00143244 MonoTouch_UIKit_UIApplication_Main_string___string_string + 300
>30 CardReader_iOS 0x000aa148 CardReader_iOS_Application_Main_string__ + 172
>31 CardReader_iOS 0x002740d0
wrapper_runtime_invoke_object_runtime_invoke_dynamic_intptr_intptr_intptr_intptr + 200
>32 CardReader_iOS 0x003c1087 mono_jit_runtime_invoke + 1134
>33 CardReader_iOS 0x003fbd2d mono_runtime_invoke + 88
>34 CardReader_iOS 0x003ff8b5 mono_runtime_exec_main + 276
>35 CardReader_iOS 0x003ff705 mono_runtime_run_main + 424
>36 CardReader_iOS 0x003af6e1 mono_jit_exec + 48
>37 CardReader_iOS 0x00432704 main + 2468
>38 libdyld.dylib 0x3a4e5ab7 <redacted> + 2
> Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries
used by your application.
Here Is My Code:
This method execute after server callback I fill data from server into a new List
public void addContacts(){
InvokeOnMainThread (delegate {
try{
tableContact.BeginUpdates();
items.AddRange(itemsAdd);
ICGlobal.contacts.AddRange(itemsAdd);
tableContact.ReloadData();
tableContact.SetNeedsDisplay();
tableContact.EndUpdates();
}catch(Exception e){
Console.WriteLine(e.StackTrace);
}
ICLayoutMgr.Get().SetBusy(false);
tableContact.ScrollEnabled = true;
});
}
this is the Custom cell class
public class ICTableContactCell : UITableViewCell
{
ICContactTableItem item;
ICContactCellView viewData;
public ICTableContactCell (ICContactTableItem item,NSString cellId) : base(UITableViewCellStyle.Default, cellId )
{
ContentView.BackgroundColor = UIColor.White;
this.item = item;
viewData = new ICContactCellView (this.item);
var view = new UIView (ContentView.Frame);
view.BackgroundColor = UIColor.Gray;
this.SelectionStyle = UITableViewCellSelectionStyle.Default;
this.SelectedBackgroundView = view;
ContentView.Add (viewData);
}
public override void LayoutSubviews ()
{
base.LayoutSubviews ();
viewData.Frame = ContentView.Bounds;
viewData.SetNeedsDisplay ();
}
public void UpdateCell (ICContactTableItem titem){
this.item = titem;
viewData.UpdateCell (titem);
}
}
public class ICContactCellView:UIView{
UILabel uiTitle;
UILabel uiCompany;
UIImageView imgSelected;
UIImageView imgDetail;
ICContactTableItem item;
static UIImage arrow=UIImage.FromFile("btnArrow.png");
static UIImage address=UIImage.FromFile("btnaddress.png");
public ICContactCellView (ICContactTableItem item)
{
this.item = item;
BackgroundColor = UIColor.White;
float yOffset = 5f;
UIColor otherColor = UIColor.Black;
uiTitle = IOTM.GUI.CreateLabel ("TITLE", yOffset+10f, yOffset, 200f, 24f, otherColor, "Helvetica-Bold", 14f);
uiCompany = IOTM.GUI.CreateLabel ("Comapany", yOffset+10f, yOffset + 16f, 200f, 24f, otherColor, "HelveticaNeue", 13f);
imgSelected =new UIImageView(){
Image = address,
Frame = IOTM.GUI.CreateFrame( yOffset+235f, yOffset+5f, 30, 30)
};
imgDetail = new UIImageView () {
Image = arrow,
Frame = IOTM.GUI.CreateFrame (280f, yOffset + 15f, 10, 10)
};
Add (uiTitle);
Add (uiCompany);
Add (imgSelected);
Add (imgDetail);
UpdateCell (this.item);
}
public void UpdateCell (ICContactTableItem titem){
this.item = titem;
if (item.index % 2 == 0)
BackgroundColor = ICGlobal.Gray;
else {
BackgroundColor = UIColor.White;
}
uiCompany.Text = "Company: " + item.enterprise;
uiTitle.Text = item.firstName+" "+item.lastName;
SetNeedsDisplay ();
}
}
TableViewSource
public class ICTableContactSource : UITableViewSource
{
public ICTableContactCell cell;
private static ICLoadMoreCell loadMore;
private ICContactTableItem itemC;
protected List<ICContactTableItem> tableItems;
protected string cellIdentifier;
public UINavigationController ParentNavigation{ get; set; }
public ICTableContactSource(List<ICContactTableItem> tl)
{
cellIdentifier = "contactCellID";
tableItems = tl;
}
public override int RowsInSection(UITableView t, int i)
{
return tableItems.Count+1;
}
public override UITableViewCell GetCell (UITableView tableView, NSIndexPath indexPath)
{
if (indexPath.Row == tableItems.Count) {
loadMore = tableView.DequeueReusableCell ("LoadingCell") as ICLoadMoreCell;
if (loadMore == null) {
loadMore = new ICLoadMoreCell (new NSString ("LoadingCell"));
}
loadMore.UpdateCell (null, 0);
return loadMore;
} else {
cell = tableView.DequeueReusableCell (cellIdentifier) as ICTableContactCell;
itemC = tableItems [indexPath.Row];
if (cell == null) {
itemC.index = indexPath.Row;
cell = new ICTableContactCell (itemC, new NSString (cellIdentifier));
cell.UpdateCell (itemC);
} else {
itemC.index = indexPath.Row;
cell.UpdateCell (itemC);
}
}
return cell as UITableViewCell;
}
public override void WillDisplay (UITableView tableView, UITableViewCell cell, NSIndexPath indexPath)
{
if (cell is ICLoadMoreCell) {
ICGlobal.currentContactView.loadMore ();
}
}