My Error Code List

When work in a project get Errors and how I solve the errors in xcode, Pod, terminal, github, swift code and crash app will be here.


 1. "Pod install" Error

Check this Error screenshot


Solution:
Pod install --repo-update


2. Crash (UILayoutPriority) when in iOS 12, in 13++ it's normal running

libc++abi.dylib: terminating with uncaught exception of type NSException
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Mutating a priority from required to not on an installed constraint (or vice-versa) is not supported. You passed priority 500 and the existing priority was 1000.'
terminating with uncaught exception of type NSException
CoreSimulator 776.4 - Device: iPhone 8 (xxxxxx-589A-xxxx-8E6B-xxxxx) - Runtime: iOS 12.4 (16G73) - DeviceType: iPhone 8

try to Debug

Debug
(lldb) po descFirstHeight.priority
▿ UILayoutPriority
- rawValue : 1000.0

(lldb) po descSecondHeight.priority
▿ UILayoutPriority
- rawValue : 500.0

(lldb) po UILayoutPriority.defaultLow
▿ UILayoutPriority
- rawValue : 250.0

(lldb) po UILayoutPriority.defaultHigh
▿ UILayoutPriority
- rawValue : 750.0

(lldb)

Solution
- In XIB dont set (priority = 1000) but you must set (prority = 999)
descFirstHeight =  999
descSecondHeight = 250

- And in file swift 

descFirstHeight.priority = UILayoutPriority.defaultLow // 250

descSecondHeight.priority = UILayoutPriority.defaultHigh // 750


Sourcehttps://stackoverflow.com/a/37474902/8366535


3. In Stackview cannot change color UIView (IOS 12)

Condition when subview in stackview 

example look like this



in phone 8 (IOS 12)



Should be like this
in Iphone 11 (IOS 15)

let see the code Before, it is because in ios 12 the process is slower than ios 15 

//// Code here ///

    private func updateDigitView(_ digitView: UIView, isHighlight: Bool) {
            digitView.backgroundColor = isHighlight ? .cyan : .clear
            
            if let bulletView = digitView.subviews.last {
                bulletView.backgroundColor = isHighlight ? .blue : .clear
                bulletView.layer.borderWidth = isHighlight ? 0 : 1
                bulletView.layer.borderColor = isHighlight ? nil : UIColor.cyan.cgColor
            }
    }


//// ----------- ///


SOLUTION

So this my solution can fix that problem use dispatchqueue async


//// Code here ///


 private func updateDigitView(_ digitView: UIView, isHighlight: Bool) {
     DispatchQueue.main.async {
            digitView.backgroundColor = isHighlight ? .cyan : .clear
            
            if let bulletView = digitView.subviews.last {
                bulletView.backgroundColor = isHighlight ? .blue : .clear
                bulletView.layer.borderWidth = isHighlight ? 0 : 1
                bulletView.layer.borderColor = isHighlight ? nil : UIColor.cyan.cgColor
            }
        }
    }


//// ----------- ///


4. Error build after (pod install)

error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.


How to Solve

- clean build/ delete DrivedData

- pod install / pod update (again)


If still an error

- checkout to branch development/master and build app.
- If in branch master not failed back into your branch and build your app again


5. 
UserDefaults JSON
this example use pod swiftyJson

// set

if let model = JSON["data"].rawString(.utf8, options: .fragmentsAllowed) {

  UserDefaults.standard.setValue(model, forKey: "UserDefaultKey")

 }


//call

guard let status = UserDefaults.standard.string(forKey: "UserDefaultKey"), let data = statusOA.data(using: .utf8else {

return nil }


6. Nil when passing data Model

When I passing optional data model like this 
example: 

In Model

struct Form: Codable {
var isValue: Bool?
var isUsed: Bool?
enum CodingKeys: String, CodingKey {
case isValue, isUsed
}

init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
isUsed = try container.decodeIfPresent(Bool.self, forKey: .isUsed)
isValue = try container.decodeIfPresent(Bool.self, forKey: .isValue)
}
}


In View Controller

var form: Form?
//When Passing from API Response
.
.
.
form = response?.form
.
.
.
print(form.isValue) // nil



Solution is  create a new request model with parameter


struct FormModel {
struct Request {
var parameters: [String: String]?

public init(isValue: Bool, isUsed: Bool) {
parameters = [
"isValue": "\(isValue)",
"isUsed": "\(isUsed)"
]
}
}
}

/////------/////------/////------/////------/////------

// in viewDidLoad example
form = FormModel.Request(isValue: true, isUsed: false)
// now is not nil

7. Error Need Install `cocoapods-keys`

Not running with Xcode Cloud, setup podfile with cocoapod-keys plugin

[!] Your Podfile requires that the plugin `cocoapods-keys` be installed. Please install it and try installation again.


The problem is my git change from `https` to `ssh` setting so my old version ruby is `2.6.1` update to `3.1.2`

Solution

- delete old `cocoapod-keys-App ` in Keychain access

$arch 

$ruby -v   

$brew     

$brew install rbenv ruby-build

$rbenv install 3.1.2  

$rbenv global 3.1.2    

$open ~/.zshrc  

$ruby -v 

$gem install cocoapods-keys

$gem install cocoapods

$gem install fastlane

$cd app    

$pod install 


8. When Cannot Run "xed ." in terminal  

This Error

app: $xcode-select --install

xcode-select: error: command line tools are already installed, use "Software Update" to install updates




Solution:

xcode-select --install

sudo xcode-select -s /Applications/Xcode.app/Contents/Developersudo xcodebuild -license accept

No comments: