Skip to content

Commit

Permalink
Merge pull request #28 from Esri/gd_swift4_migration
Browse files Browse the repository at this point in the history
Migration to Swift 4
  • Loading branch information
Garima Dhakal authored Mar 26, 2018
2 parents e879d67 + e3a15e9 commit e00c861
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 32 deletions.
22 changes: 18 additions & 4 deletions Toolkit/ArcGISToolkit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,12 @@
881233671DF601A700B2EA8E /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0820;
LastUpgradeCheck = 0920;
ORGANIZATIONNAME = Esri;
TargetAttributes = {
8812336F1DF601A700B2EA8E = {
CreatedOnToolsVersion = 8.0;
LastSwiftMigration = 0820;
LastSwiftMigration = 0920;
ProvisioningStyle = Automatic;
};
};
Expand Down Expand Up @@ -227,15 +227,21 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_SUSPICIOUS_MOVES = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
Expand Down Expand Up @@ -281,15 +287,21 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_SUSPICIOUS_MOVES = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
Expand Down Expand Up @@ -340,7 +352,8 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
};
name = Debug;
};
Expand All @@ -364,7 +377,8 @@
PRODUCT_BUNDLE_IDENTIFIER = com.esri.ArcGISToolkit;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
};
name = Release;
};
Expand Down
2 changes: 1 addition & 1 deletion Toolkit/ArcGISToolkit/Compass.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public class Compass: UIImageView {
mapView.removeObserver(self, forKeyPath: #keyPath(AGSMapView.rotation), context: &kvoContext)
}

func compassTapped(){
@objc func compassTapped(){
mapView.setViewpointRotation(0, completion: nil)
isHidden = autoHide
}
Expand Down
18 changes: 9 additions & 9 deletions Toolkit/ArcGISToolkit/MeasureToolbar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ class MeasureResultView : UIView{
stackView.topAnchor.constraint(equalTo: topAnchor).isActive = true
stackView.heightAnchor.constraint(equalToConstant: 32).isActive = true

valueLabel.setContentCompressionResistancePriority(500, for: .horizontal)
valueLabel.setContentHuggingPriority(1000, for: .horizontal)
valueLabel.setContentCompressionResistancePriority(UILayoutPriority(rawValue: 500), for: .horizontal)
valueLabel.setContentHuggingPriority(.required, for: .horizontal)

unitButton.setContentCompressionResistancePriority(499, for: .horizontal)
unitButton.setContentHuggingPriority(1000, for: .horizontal)
unitButton.setContentCompressionResistancePriority(UILayoutPriority(rawValue: 499), for: .horizontal)
unitButton.setContentHuggingPriority(.required, for: .horizontal)

let tgr = UITapGestureRecognizer(target: self, action: #selector(buttonTap))
addGestureRecognizer(tgr)
Expand All @@ -111,7 +111,7 @@ class MeasureResultView : UIView{
return true
}

func buttonTap(){
@objc func buttonTap(){
guard unitButton.isHidden == false else{
return
}
Expand Down Expand Up @@ -376,18 +376,18 @@ public class MeasureToolbar: UIView, AGSGeoViewTouchDelegate {
let space : CGFloat = 2

let c1 = resultView.leadingAnchor.constraint(greaterThanOrEqualTo: leftHiddenPlaceholderView.trailingAnchor, constant: space)
c1.priority = UILayoutPriorityRequired
c1.priority = .required

// have to give this just below required, otherwise before the left and right views are setup in
// their proper locations we can get constraint errors
let c2 = resultView.trailingAnchor.constraint(lessThanOrEqualTo: rightHiddenPlaceholderView.leadingAnchor, constant: -space)
c2.priority = UILayoutPriorityRequired-1
c2.priority = UILayoutPriority(rawValue: 999)

let c3 = NSLayoutConstraint(item: resultView, attribute: .centerX, relatedBy: .greaterThanOrEqual, toItem: toolbar, attribute: .centerX, multiplier: 1, constant: 0)
c3.priority = UILayoutPriorityRequired
c3.priority = .required

let c4 = NSLayoutConstraint(item: resultView, attribute: .centerX, relatedBy: .lessThanOrEqual, toItem: toolbar, attribute: .centerX, multiplier: 1, constant: 0)
c4.priority = UILayoutPriorityDefaultLow
c4.priority = .defaultLow

NSLayoutConstraint.activate([c1, c2, c3, c4])

Expand Down
36 changes: 18 additions & 18 deletions Toolkit/ArcGISToolkit/Scalebar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public class Scalebar: UIView {
}
}

public var font : UIFont = UIFont.systemFont(ofSize: 9.0, weight: UIFontWeightSemibold){
public var font : UIFont = UIFont.systemFont(ofSize: 9.0, weight: UIFont.Weight.semibold){
didSet{
recalculateFontProperties()
updateScaleDisplay(forceRedraw: true)
Expand Down Expand Up @@ -283,13 +283,13 @@ public class Scalebar: UIView {
private func recalculateFontProperties(){

let zeroText = "0"
zeroStringWidth = zeroText.size(attributes: [NSFontAttributeName: font]).width
zeroStringWidth = zeroText.size(withAttributes: [NSAttributedStringKey.font: font]).width

let fontHeightText = "Ay"
fontHeight = fontHeightText.size(attributes: [NSFontAttributeName: font]).height
fontHeight = fontHeightText.size(withAttributes: [NSAttributedStringKey.font: font]).height

let unitsMaxText = " km"
maxRightUnitsPad = unitsMaxText.size(attributes: [NSFontAttributeName: font]).width
maxRightUnitsPad = unitsMaxText.size(withAttributes: [NSAttributedStringKey.font: font]).width
}

// set a minScale if you only want the scalebar to appear when you reach a large enough scale
Expand Down Expand Up @@ -619,9 +619,9 @@ internal extension ScalebarRenderer{
// use a string with at least a few characters in case the number string only has 1
// the dividers will be decimal values and we want to make sure they all fit
// very basic hueristics...
let minSegmentTestString = (scaleDisplay.mapLengthString.characters.count > 3) ? scaleDisplay.mapLengthString : "9.9"
let minSegmentTestString = (scaleDisplay.mapLengthString.count > 3) ? scaleDisplay.mapLengthString : "9.9"
// use 1.5 because the last segment, the text is right justified insted of center, which makes it harder to squeeze text in
let minSegmentWidth = (minSegmentTestString.size(attributes: [NSFontAttributeName: scalebar.font]).width * 1.5) + (Scalebar.labelXPad * 2)
let minSegmentWidth = (minSegmentTestString.size(withAttributes: [NSAttributedStringKey.font: scalebar.font]).width * 1.5) + (Scalebar.labelXPad * 2)
var maxNumSegments : Int = Int(lineDisplayLength / minSegmentWidth)
maxNumSegments = min(maxNumSegments, 4) // cap it at 4
let numSegments: Int = ScalebarUnits.numSegmentsForDistance(distance: scaleDisplay.lineMapLength, maxNumSegments: maxNumSegments)
Expand All @@ -637,7 +637,7 @@ internal extension ScalebarRenderer{
currSegmentX += segmentScreenLength
let segmentMapLength = Double((segmentScreenLength * CGFloat(index + 1)) / lineDisplayLength) * scaleDisplay.lineMapLength
let segmentText = Scalebar.numberFormatter.string(from: NSNumber(value: segmentMapLength)) ?? ""
let segmentTextWidth = segmentText.size(attributes: [NSFontAttributeName: scalebar.font]).width
let segmentTextWidth = segmentText.size(withAttributes: [NSAttributedStringKey.font: scalebar.font]).width

let segmentInfo = SegmentInfo(index: index, segmentScreenLength: segmentScreenLength, xOffset: currSegmentX, segmentMapLength: segmentMapLength, text: segmentText, textWidth: segmentTextWidth)

Expand All @@ -659,19 +659,19 @@ internal extension ScalebarRenderer{
// draw text shadow
if let shadowColor = scalebar.textShadowColor{

let shadowAttrs = [NSFontAttributeName: scalebar.font,
NSParagraphStyleAttributeName: paragraphStyle,
NSForegroundColorAttributeName: shadowColor]
let shadowAttrs = [NSAttributedStringKey.font: scalebar.font,
NSAttributedStringKey.paragraphStyle: paragraphStyle,
NSAttributedStringKey.foregroundColor: shadowColor]

let shadowFrame = frame.offsetBy(dx: shadowOffset.x, dy: shadowOffset.y)

text.draw(with: shadowFrame, options: .usesLineFragmentOrigin, attributes: shadowAttrs, context: nil)
}

// draw text
let attrs = [NSFontAttributeName: scalebar.font,
NSParagraphStyleAttributeName: paragraphStyle,
NSForegroundColorAttributeName: textColor]
let attrs = [NSAttributedStringKey.font: scalebar.font,
NSAttributedStringKey.paragraphStyle: paragraphStyle,
NSAttributedStringKey.foregroundColor: textColor]

text.draw(with: frame, options: .usesLineFragmentOrigin, attributes: attrs, context: nil)
}
Expand Down Expand Up @@ -711,7 +711,7 @@ internal extension ScalebarRenderer{
// draw units off the end

let unitsText = " \(scaleDisplay.displayUnit.abbreviation)"
let unitsTextWidth = unitsText.size(attributes: [NSFontAttributeName: scalebar.font]).width
let unitsTextWidth = unitsText.size(withAttributes: [NSAttributedStringKey.font: scalebar.font]).width

let unitsTextFrame = CGRect(x: segmentTextFrame.maxX,
y: textY,
Expand Down Expand Up @@ -1361,10 +1361,10 @@ internal class ScalebarDualUnitLineStyleRenderer : ScalebarRenderer{
// draw top text

let topUnitsText = " \(scaleDisplay.displayUnit.abbreviation)"
let topUnitsTextWidth = topUnitsText.size(attributes: [NSFontAttributeName: scalebar.font]).width
let topUnitsTextWidth = topUnitsText.size(withAttributes: [NSAttributedStringKey.font: scalebar.font]).width

let topText = "\(scaleDisplay.mapLengthString)\(topUnitsText)"
let topTextWidth = topText.size(attributes: [NSFontAttributeName: scalebar.font]).width
let topTextWidth = topText.size(withAttributes: [NSAttributedStringKey.font: scalebar.font]).width
let topTextMapLengthStringWidth = topTextWidth - topUnitsTextWidth

let topTextFrame = CGRect(x: lineX + lineScreenLength + halfLineWidth - topTextMapLengthStringWidth,
Expand All @@ -1378,10 +1378,10 @@ internal class ScalebarDualUnitLineStyleRenderer : ScalebarRenderer{
if let numberString = Scalebar.numberFormatter.string(from: NSNumber(value: otherLineMapLength)){

let bottomUnitsText = " \(otherDisplayUnits.abbreviation)"
let bottomUnitsTextWidth = bottomUnitsText.size(attributes: [NSFontAttributeName: scalebar.font]).width
let bottomUnitsTextWidth = bottomUnitsText.size(withAttributes: [NSAttributedStringKey.font: scalebar.font]).width

let bottomText = "\(numberString)\(bottomUnitsText)"
let bottomTextWidth = bottomText.size(attributes: [NSFontAttributeName: scalebar.font]).width
let bottomTextWidth = bottomText.size(withAttributes: [NSAttributedStringKey.font: scalebar.font]).width
let bottomTextNumberStringWidth = bottomTextWidth - bottomUnitsTextWidth

let bottomTextFrame = CGRect(x: lineX + otherLineScreenLength + halfLineWidth - bottomTextNumberStringWidth,
Expand Down

0 comments on commit e00c861

Please sign in to comment.