9 Notes October 2021

1. *** Terminating app due to uncaught exception 'NSUnknownKeyException'

when you find this crash below it mean in xib file has error outlet, to fixiing that check your .xib and remove the error outlet in outlet collection.


"'

*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<Module.yourView 0x7f929006e6f0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key view.'

"'
enter image description here






2. *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle


*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle


This error is your NSBundle is wrong target, example in my code is error in tableview register


//Before
tableView.register(UINib(nibName: "YourTableCell", bundle: nil, forCellReuseIdentifier: "cell")

// Solution is fixing handle bundle
//After

import UIKit

public extension UITableView {
    
    func registerNibFromBundle(_ cellClass: UITableViewCell.Type) {
        register(UINib(nibName: String(describing: cellClass), bundle: Bundle(for: cellClass)), forCellReuseIdentifier: cellClass.reuseIdentifier)
    }
}

//viewcontrolller how to use
import UIKit

class YourViewController {
override func viewDidLoad() { super.viewDidLoad()             tableView.delegate = self      tableView.dataSource = self      tableView.registerNibFromBundle(YourTableCell.self)   } }

3.  *** Terminating app - cannot load header view tableView

This error look like this
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </Users/xxxx/Library/Developer/Xcode/DerivedData/xxx-xxxx/Build/Products/Development-iphonesimulator/Trading.framework> (loaded)' with name 'HeaderBrokerageFirm''
Solution is :

delete header height tableview or you can delete HeaderView outlet and replace them again.

//before

    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) - > UIView? {
        let view = HeaderView().loadViewFromNib() as! HeaderView
return view } func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { return 150 } //after
    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) - > UIView? {
        let view = HeaderView().loadViewFromNib() as! HeaderView
return view }


4. Dynamic count enum in swift

Some case I don't know how to make count in enum to be dynamic see this example code below, you can call this function into numberOfItems in tableView count index or collectionView item. in manual return you can choose two type manual integer or  use case name to indexing.

enum beEnum {
    case id
    case account
    case name
    case other

}
import UIKit

class YourViewController {
func numberIndex() -> Int {      if wantTwoIndex == false {         // use enum to count all            return beEnum.allCases.count      } else {          // use manual count to what you want           return 2           // Or you can count by case enum           return [beEnum.id, beEnum.account].count      }
} }
5. String Character count update in swift4 +

When I search about how to count string code on this blog I've found bug "str.character.count" cannot be use anymore. so after search in stackoverflow I found that because code already update.
and this update should fixing that bug.

let str: String = "you string"

//before swift 2 / 3
print(str.characters.count) // 10
//After swift4 + print(str.count). // 10


6. Don't use "viewForHeaderInSection"

Note: If you need header to table view but you want to scroll header to you just use "+1" in numberOfRowsInSection.


7. Error when Create model

Type 'FormResponse' does not conform to protocol 'Encodable'


solution is
You can't use Any together with Codable, that's what is wrong. What do you mean with "my users"? 


8. Failed install CocoaPod


source: Author



[!] Invalid `Podfile` file: undefined method `enable_bitcode_for_prebuilt_frameworks!' 




when I get this error, I search what can fixing for this error.  if i install pods in new project no problem
so this my solution 

first install  cocoapods-binary

$ sudo gem install cocoapods-binary
$ sudo gem install ffi $ sudo gem install cocoapods-keys $ pod install

this image below is error need install cocoapod keys, after your finish install this, you can install cocoapod

source: Author



9.  Different variable Optional and brackets



Use array optional you will be get nil if you want to appand that and condition use brackets 
you can add data to your array

====================================================

Handle height tableview auto height into cell
https://21zerixpm.medium.com/tableview-in-uitableviewcell-3c7cf123d969

====================================================


No comments: