9 Notes November 2020

 1. Error Multiple commands produce

That error can be fixing in signing and capabilities  if u have an apple developer program it will be fine

Example error

Multiple commands produce '/Users/xxx/Library/Developer/Xcode/DerivedData/xxxx-xxxx/
Build/Products/Master-iphonesimulator/xxxx.swiftmodule/x86_64.swiftmodule':
Target 'xxxx' (project 'xxxx'): Ditto /Users/xxxx/Library/Developer/Xcode/DerivedData /xxxx-xxxxx/Build/Products/Master-iphonesimulator/xxxx. swiftmodule/x86_64.swiftmodule /Users/xxxx/Library/Developer/Xcode/DerivedData/ xxxxxxx-xxxxxx/Build/Intermediates.noindex/xxxxx.build/ Master-iphonesimulator/xxxx.build/Objects-normal/x86_64/xxxxx.swiftmodule

How to solve this bug

Source: http://scripttes.blogspot.com/2020/04/9-notes-in-march-2020.html
and https://stackoverflow.com/questions/55856786/error-multiple-commands-produce-x86-64-swiftmodule


2. Error Build input file cannot be found: '/Users/userxxx/IOS//Appxx/Appxx/xxxx/Info.plist'

For fixing this error Go to tab 'Bulid Setting ' and find info.plist in section Packaging


Change value location where your move Info.plist, example :

From
App/Info.plist

To
App/Support/Info.plist


3. How To Exit VIM? (In Terminal)

I've got a problem like you, so  just follow this step

Step 1: Enter the command mode by pressing Esc key
Press Esc key: This is very important, because you must exit the edit mode first 
before typing the exit command(s).

Step 2: Quit vim using commands
Next, you can type one of the following commands to exit Vim in different mode:

:q (yes, the colon is included in the command) – This will quit the editor. 
    It may prompt you if you are trying to exit Vim and there are unsaved changes.
:q! – Quit Vim without saving the data file (all unsaved changes are discarded).
:wq – Save the file and exit Vim.

4. Setup Swiftlint  (For Clean Code)

-  First Brew Intall in terminal

$ brew install swiftlint

- Step two Install pod swiftlint

- Step three is paste this snippet (Build  Phase -> Plus Button (New Run Script Phase))

if which swiftlint >/dev/null; then
  swiftlint
else
  echo "warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint"
fi


- Step four open terminal  in project

 $ touch .swiftlint.yml  
 
 check data with  

$ ls  -a


if you find file (.swiftlint.yml) open it or you can use visual studio code to  paste this code  below
note: put all your folder into visual studio and you can find (.swiftlint.yml)


# By default, SwiftLint uses a set of sensible default rules you can adjust:
disabled_rules: # rule identifiers turned on by default to exclude from running
  - colon
  - comma
  - control_statement
opt_in_rules: # some rules are turned off by default, so you need to opt-in
  - empty_count # Find all the available rules by running: `swiftlint rules`

# Alternatively, specify all rules explicitly by uncommenting this option:
# whitelist_rules: # delete `disabled_rules` & `opt_in_rules` if using this
#   - empty_parameters
#   - vertical_whitespace

included: # paths to include during linting. `--path` is ignored if present.
  - Source
excluded: # paths to ignore during linting. Takes precedence over `included`.
  - Carthage
  - Pods
  - Source/ExcludedFolder
  - Source/ExcludedFile.swift
  - Source/*/ExcludedFile.swift # Exclude files with a wildcard
analyzer_rules: # Rules run by `swiftlint analyze` (experimental)
  - explicit_self

# configurable rules can be customized from this configuration file
# binary rules can set their severity level
force_cast: warning # implicitly
force_try:
  severity: warning # explicitly
# rules that have both warning and error levels, can set just the warning level
# implicitly
line_length: 110
# they can set both implicitly with an array
type_body_length:
  - 300 # warning
  - 400 # error
# or they can set both explicitly
file_length:
  warning: 500
  error: 1200
# naming rules can set warnings/errors for min_length and max_length
# additionally they can set excluded names
type_name:
  min_length: 4 # only warning
  max_length: # warning and error
    warning: 40
    error: 50
  excluded: iPhone # excluded via string
  allowed_symbols: ["_"] # these are allowed in type names
identifier_name:
  min_length: # only min_length
    error: 4 # only error
  excluded: # excluded via string array
    - id
    - URL
    - GlobalAPIKey
reporter: "xcode" # reporter type (xcode, json, csv, checkstyle, junit, html, emoji, sonarqube, markdown, github-actions-logging)

- Step five  in (Sorce ) change to your name Project and save

included: # paths to include during linting. `--path` is ignored if present.
  - Source

- Last rebuild your project and you can see how much warning/ error in your code that because it work  

Source: 
https://github.com/realm/SwiftLint
https://www.youtube.com/watch?v=MJcBhc59eu8&ab_channel=CodePro

5. Replacing Extension String with template 

let stringTemplate = "Top Up %@ Complete."
let value = "$500" let tooop =  topUp.replaceString(with: value) print(tooop)
extension String {
    func replaceString(with: String) -> String {       return self.replacingOccurrences(of: "%@", with: with)     } }



6. Ignoring json-2.3.1 because its extensions are not built. Try: gem pristine json --version 2.3.1

Error in terminal "pod install"

// Try this in terminal
$gem pristine --all

// if found error like this
You don't have write permissions for the /Library/Ruby/Gems/2.6.0 directory.

//If you don't want to run sudo then install ruby using homebrew
$ brew install ruby
export GEM_HOME="$HOME/.gem"
$ gem install rails
source: 
https://stackoverflow.com/a/39866401/8366535
&
https://stackoverflow.com/a/53949737/8366535

7. Protocol Property (get, get set)

Example:

protocol  SomeProtocol {

var username: String? { get set  }

var count:  Int { get }

}


sourcehttps://medium.com/@chetan15aga/swift-protocols-properties-distinction-get-get-set-32a34a7f16e9

8. How to use AnyHashable

Example:

let descriptions: [AnyHashable: Any] = [

AnyHashable("message"): [ "data" : [ "isevent" : false, "eq" : -1, "fId" : "random-e1e7-42a9-b170", "msgId" : "random-48dd-94b6-f4fdd60f1427", "type" : "Tll_user", "userId" : "1111OHWTSo" ], "type" : "incoming" ], AnyHashable("aps"): ["content-available": 1], AnyHashable("gcm.message_id"): 1606158132170310, AnyHashable("google.c.sender.id"): 380018016469 ]


9. Array Append use contentOf


 // Diffrent use "append( ) and "append(contentOf: )" is

// 1. .append() for single add value example:

var array: [String] = ["a"] 
array.append("new")
print(array) // ["a", "new"]
// 2. .append(contentOf: ) for multiple add value example: var array: [String] = ["a"] array.append(     ["new1", "new2", "new3"] ) print(array) // ["a", "new2", "new3"]





No comments: