preface

I started my first day of Swift in the light of the situation that I have no job and I feel tired to read the interview.

For Swift, I also belong to the 0 foundation. I have learned a long time ago, but it has no reference significance for many years

plan

The first stage

It's basically basic learningCopy the code
  • His ownPodThe warehouse is set up, first build a basic learning grammarPodComponent Module.
  • Put the common enough brush some basic grammar and knowledge record.

The second stage

Start from the basic data structure brush, temporarily intended to be two simple questions, two medium questions such. Try to find something representative. Mostly for the recordCopy the code
  • Array, linked list, queue, stack, tree, dictionary
  • Backtracking, DFS, BFS, etc.

The third stage

The entire UI framework is systematically learned, then combined with some previously little-used design patterns, starting from zero. Slowly to do.Copy the code
  • Inheritance structure
  • Do a small project, scratch the interface

The fourth stage

After having the foundation, the characteristics of OC, what KVC, KVO and some other mechanisms step by step the optimization and difference of various mechanisms compared with Swift. Better understanding of the advantages of language, including network layer, database, etc. And said the UI interface optimization.Copy the code
  • Comparative, and a bit of depth to learn a little bit.

conclusion

Study as hard as you can. For ordinary people, history is always proving whether to advance or go back.

In fact, the truth is, if you want to eat and wait for death, you have to keep a good attitude and state of study, you can not advance or retreat.

No matter what you do, no matter where your passion is, your priority is to keep up with The Times.

Creating a Pod warehouse

Today I will first do the Swift warehouse and simple components, the following is only for records. The official documentation

    1. Create a public repository on Github, Choose a license, select MIT, and add README.
    1. Get the address of the Git repository you just created and drag it to your local directory.(My name is JKSwiftSpec)
    1. pod repo add JKSwiftSpec xxx.git
    1. Test the
    • open .cocoapods/reposOpen the local computer by running a commandPod warehouseSee if there’s anyJKSwiftSpecThe folder, if any, is pulled successfully

This is our own open warehouse.

Creating a Pod component

In any directory, let’s say we’re on the desktop. The library I created is called JKSwiftZero

    1. pod lib create JKSwiftZero
    • Success will automatically pop upPodProject, there will be one on the desktopJKSwiftZeroFolder with the entire project file below and the diagram below.
    • The following is the time to choose according to their own needs, the last two are to integrate some testing framework. Usually not
What platform do you want to use?? [ iOS / macOS ]
 >
ios
What language do you want to use?? [ Swift / ObjC ]
 >
swift
Would you like to include a demo application with your library? [ Yes / No ]
 >
yes
Which testing frameworks will you use? [ Quick / None ]
 > None

Would you like to do view based testing? [ Yes / No ]
 > No
Copy the code

    1. Then open theExampleEngineering within engineering.add files to ...., as shown below:

Put the project outsideJKSwiftZeroPull in the project. You can make changes. Note:

1. Select Create Groups only. Do not copy and do not rely on Add to Targets with the project Settings.

2. When removing, do not remove to crash, just remove from the project. Otherwise, external files will be damaged.

    1. We can modify our project now, directly inExample for JKSwiftZeroThe interior just pulled in the place of modification.
    • Remove the original replaceMe,.gitkeep and other files, and create a new file.
    1. Find it directly in the top level structure of the projectJKSwiftZero.podspec, this path is the same as the outermost file, you can change it here. Here are the changes:
Pod::Spec.new阿鲁纳恰尔邦do** |s|
    s.name             = 'JKSwiftZero'
    s.version          = '1.0.0'
    s.summary          = 'JKSwiftZero learns from zero '

    s.description      = <<-DESC
    TODO: Add longFrom DESC S.Hemepage ='https://github.com/nbkey/JKSwiftZero'
    # s.screenshots     = 'www.example.com/screenshots_1'.'www.example.com/screenshots_2'
    s.license          = { :type => 'MIT', :file => 'LICENSE' }
    s.author           = { 'nbkey'= >'[email protected]' }
    s.source           = { :git => 'https://github.com/nbkey/JKSwiftZero.git', :tag => s.version.to_s }
    
    s.ios.deployment_target = '10.0'
    s.source_files = 'JKSwiftZero/Classes/**/*'
    #s.resource_bundles = {
    #    'JKSwiftZero'= > ['JKSwiftZero/Assets/*']
    #}

    # s.public_header_files = 'Pod/Classes/**/*.h'

    # s.frameworks = 'UIKit'.'MapKit'

    # s.dependency 'AFNetworking'.'~ > 2.3'

**end**
Copy the code
  • homepage:github: Access to private libraries is generally not included.gitWe haven’t created it yet.
  • source:github: Address for uploading the private library.
  • resource_bundles: Resource file
  • source_files: Code file
  • version: the version number

Then it goes as follows:

And then againpod install, the project is programmed as shown below:

swiftClass that you want to accesspublicModified, otherwise inaccessible. You only need to import the library name, not a separate file name. There are some other modifiers that I haven’t looked at systematically yet, but I’ll get to that.

After modifying the Podspec and deleting the files, the local installation is complete and you are ready to upload to the cloud.

    1. Go to thegithubCreate a public library and get the address.
git add .
git commit -m 'First initialization'
git remote add origin https://github.com/nbkey/JKSwiftZero.git
git push origin master  (Sometimes it does443, some people set the agent, can also keep trying, for a while good for a while bad)Git tag '1.0.0/** Git use some records **/
git remote show origin  (This command allows you to view tracing relationships.)Git push -u origin master the git push -u origin master command pushes the local branch to the origin host and specifies origin as the default host. Git push without any parameters, only the current branch is pushed by default, this is called simple mode. git config --global push.defaultWith simple matching, all local branches that have corresponding remote branches are pushed. Before Git 2.0, matching was the default. Now, simple is the default. To change this setting, use the git config command.Copy the code

At this point the remote private library will already be available.

    1. Next, put theJKSwiftZeroLibrary to add to their own# JKSwiftSpecinside
1.Configure a pod trunk me if you have a pod account2.Local validation: this step is quite slow, you must verify the validity of the file before you can upload it, preferably locally7.We changed the minimum swift dependency setting in the project to5.0.
    2.1Change the Swift Language Version of the build setting to5.0, pod2.2Change the project's iOS Deployment Target to10.0
    2.3Change Podfile to platform :ios,'10.0'Pod lib Lint --allow-warnings this allows continued validation to pass warnings3.Verbose is for full errors, --allow-warnings is for ignoring warnings, --no-clean Pod spec Lint --verbose --allow-warnings4.This command is added to cocoapods libraries. If the static library containing. A cannot be verified, Pod Trunk push jkSwiftZer. podspec --verbose --allow-warnings5.This command is added to the JKSwiftSpec library you created, pod repo push JKSwiftSpec jkSwiftZer. podspec --verbose --allow-warnings// Some notes
// You can view all commandsPod lib lint --help (see all optional arguments, optional arguments can be added)// Enable this function in the Podfile to do several small projects
install! 'cocoapods', :generate_multiple_pod_projects => true 

// Directory hierarchy needs to be set,S.subspec 'directory name'do| | ss ss. Scoure_files = 'Classes/directory name/ * * /* '//vendored_libraries: configure the non-system static libraries that you want to reference.
vendored_libraries = 'Frameworks/libZCPKit.a'

// The sublevels cannot be dependent on each other. If the repo is dependent on each other, it will fail to commit

// Resource_bundles will be added to the subproject. The main project will use the asset and will fail validation.

end

Copy the code

Cocoapods warehouse

See what 443, http2 error, all is the network fault, too vomit blood.

Some common pits

There are always problems with the POD library

Failure of validation of resource_Bundles

  • It says, put it in a subproject, import the path.
s.subspec 'Public' do |ss|
    ss.resource_bundles = {
          'PublicImg'= > ['ServicePublic/Assets/*.png'].'PublicSql'= > ['ServicePublic/Classes/Public/SQL/UserDataTable/*.sql'].'PublicXib'= > ['ServicePublic/Classes/Public/**/*.xib']
      }
end

**/ *Copy the code

Private libraries depend on both private and public libraries?

  • Set up thedependencyCan be

How do private libraries function when pushed to Podspec’s index repository?

  • inpod repo push JKSwiftSpec JKSwiftZero.podspec --verbose --allow-warningsFollowed by--skip-import-validation
  • skipimportA charm
  • Must ensure that there is no problem in the shell project, can POD up.

Access to private library images, niBs and other resources?

  • The main thing is to need a POD project class throughBoundletherescourePath+ Splice hard code to get the correspondingbundleAnd other documents.

OC just search a lot

The new PodSpec released is not updated to git for the component’s library.

  • pod cache clean –all
  • pod update
  • pod install

conclusion

Not very well, the network problem, pushed the warehouse for two hours… All things are difficult before they are easy

Hold on slowly…