9 NOTES IN JULY 2020



1. Error: Your local changes to the following files would be overwritten by checkout:

Please move or remove them before you switch branches.
Aborting

solution use this
git checkout -f sprint/4-temp
git checkout -f master

note: -f (force)

2. Disable / DeAllow copy paste in UITextField

This solution for disable action paste in UITextField

class CustomTextField: UITextField {
    var enableLongPressActions = false
    required init(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)!
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
    }

    override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
        return enableLongPressActions
    }
}

      

3. Change Author name specific commit


- $git config --global user.name "name user"
- $git pull develop  (<- name branch) 
- $git push develop  (<- name branch)

before change author name cek config 

- $git config --list 


4. Error Stuct passing data

in condition I try to  call struct  
example 

var myStruct: ListStruct?  <- if use optional it's ok
var myStruct = ListStruct() <- error

and error will be 

initializer is inaccessible due to 'internal' protection level

in xcode solution: You can use public init (public),  if you use framework (different module example use VIPER module) and you call function from  framework to your project so use this solution 

set optional value in your project and framework set default value
example in condition you want to push from project to framework

In project. (Example in code)

var optionalValue: optionalValueStruct?


// you can use in view didload
sendModule(optionalValue: optionalValue)


public func sendModule(optionalValue: value?) -> UIViewController {
     return Configurator.shared.Module(value: optionalValue)
 }
In framework.   (Example in code)


public func createOwnListTransferDetailModule(value: optionalValue?) -> UIViewController {
        guard let value = optionalValue else {return nil}

        var defaultValue = DefaultValueStruct()
        defaultValue.username = value.username

       return defaultValue
 }




5. Reset all git branch (but not create new branch)

I want name branch not change just need to reset all like new branch
this below change one file from some branch to your branch

example :
git checkout origin/development -- HomeApp/Views/Home.swift

I know if I want to change one file from another branch into my branch, but I need to pull all from some branch to my branch (Change all),  a lot search finnaly i found this 

git reset --hard origin/development


6.  Draw vertical dot line swift

Draw line this easy use with extension 


public extension UIView {
    private static let lineDashPattern: [NSNumber] = [5, 5]
    private static let lineDashWidth: CGFloat = 1.0
    
    func drawVetricalDotLine() {
        let lineLayer = CAShapeLayer()
        lineLayer.strokeColor = UIColor.lightGray.cgColor
        lineLayer.lineWidth = 4
        lineLayer.lineDashPattern = UIView.lineDashPattern
        let path = CGMutablePath()
        path.addLines(between: [CGPoint(x: bounds.origin.x, y: bounds.origin.y),
                                CGPoint(x: bounds.origin.x, y: bounds.size.height)])
        lineLayer.path = path
        layer.addSublayer(lineLayer)
        self.clipsToBounds = true
    }
}

How to use example:

verticalSubview.drawVrticalDotLine()



7. Custom Operator in Swift

Source: 

// MARK: Custom Operators in Swift
prefix operator !!
extension String {
     static prefix func !! (name: String) -> String {
           return "Hello " + name
     }
}

infix operator ^^: MultiplicationPrecedence
extension Int {
      static func ^^ (num: Int, power: Int) -> Int {
           return Int(pow(Double(num), Double(power)))
      }
}

postfix operator %
extension Double {
       static postfix func % (percentage: Double) -> Double {
              return (Double(percentage) / 100)
       }
}
How to use :

print(!!"There") // Hello There
print(0 ^^ 5) // 0
print(3 % 9) // 3


8.  Check spelling While typing XCODE

Edit > Format > Spelling and Grammar
Checklist this (Check spelling While typing)




9. Conditional breakpoint

 You can make a breakpoint that only stops code under a certain condition.
You can setup a breakpoint and then right-click on that breakpoint and select









No comments: