[Tips] How to solve problems with XCode and Swift for beginners


macOS:Catalina 10.15.6 Xcode:12.0 Swift:5.3

About the author

I'm just an engineer studying swift as a hobby. I don't use it at all at work. I studied swift once around 2015, and recently rekindled and re-studied.

1. Stack View cannot be constrained well

If the value of spacing contains a value other than 0, it seems that the constraint will be affected, so It is better to enter 0 for spacing (anywhere that does not affect the constraint). スクリーンショット 2020-10-18 19.50.23.png

2. When I create a new class and inherit the protocol, I get a warning.

Cannot declare conformance to 'NSObjectProtocol' in Swift; I get angry. In this case, ʻimport Foundation and then inheriting NSObject is the solution. In my case, it was difficult because I deleted ʻimport Foundation and tried and errored.

3. Build error

Multiple commands produce XXX occurs. If you look closely, Target [app name] has copy command from XXX and Target [app name] has link command with output XXX occur. After a little research, something seemed to be in conflict. I think it was bad to manually copy the .swift file on XCode. I wasn't sure, so I solved it by recreating the project. The problem was solved by copying XXX.swift and Main.storyboard from the old project folder to the new project folder on Finder. I didn't know the location of Main.storyboard for a moment, but on Finder, it is in ... / [app name] / [app name] /Base.Iproj/.

4. I want to adjust the object in proportion (such as TableView with 40% height)

The site of here will be helpful.

5. Text does not break

I want to insert a line feed code and start a new line at any place, but it does not. It didn't seem to work with \ n, so I had to type \ n. You can enter \ by holding down the ʻoption key and pressing \ `.

6. Cannot connect to .swift file ʻOutlet, ʻAction

I created a new ViewController such as the transition destination and tried to connect with the same as the ViewController from the beginning, but only the ʻObject item can select ʻExit. スクリーンショット 2020-10-24 21.32.08(2).png

Select the target ViewController on the Storyboard. Select the class corresponding to ViewController from Custom Class of ʻIdentity Inspector`. (Image modified) スクリーンショット 2020-10-24 21.37.51(2).png

7. I can't go out with TableView

In order to prevent the bloat of ViewController, you can create a separate class that inherits ʻUITableViewDelegate and ʻUITableViewDataSource and delegate the processing to that class. In this case, there are some points to be aware of. The instance of the class to be delegated must be created outside viewDidLoad (). Well, if you think about it for a moment, it's natural. If the delegation destination is ViewController (yourself), it works fine even if you create an instance inviewDidLoad (). Although it deviates from the main subject, if you want to instantiate in viewDidLoad () due to timing problems (if you want to do it after some processing), just declare variables outside viewDidLoad () and There is no problem if you substitute it in viewDidLoad ().

Recommended Posts

[Tips] How to solve problems with XCode and Swift for beginners
Common problems with WSL and how to deal with them
Must-see for beginners! How to manage your Xcode project on Github
[Ruby] How to use slice for beginners
[For beginners] How to debug in Eclipse
[Swift] How to connect TabBar with Storyboard Reference and also use NavigationController
(For beginners) [Rails] Time saving tech! How to install and use slim
Java8 / 9 Beginners: Stream API addiction points and how to deal with them
[Swift / For beginners] Write smartly with type inference
[Java] How to test for null with JUnit
[Swift] How to link the app with Firebase
[For beginners] How to implement the delete function
How to build API with GraphQL and Rails
How to use nginx-ingress-controller with Docker for Mac
[For super beginners] How to use autofocus: true
I'm making an Android app and I'm stuck with errors and how to solve it
How to set up computer vision for tracking images and videos with TrackingJs
How to implement UICollectionView in Swift with code only
How to implement login request processing (Rails / for beginners)
How to build docker environment with Gradle for intelliJ
[For beginners] Let's be able to coat like Swift!
How to deal with No template for interactive request
[For beginners] How to operate Stream API after Java 8
[Spring Boot] How to create a project (for beginners)
How to serialize and deserialize LocalDateTime type with GSON
How to quit Docker for Mac and build a Docker development environment with Ubuntu + Vagrant
How to make Laravel faster with Docker for Mac
How to use RealSense with ubuntu 20.04 and ROS Noetic
How to install Gradle and Kotlin with SDKMAN (Mac)
Explanation of Ruby on rails for beginners ④ ~ Naming convention and how to use form_Tag ~
How to use GitHub for super beginners (team development)
How to add another project as Maven library with CircleCI and use it for build
[For Swift beginners] I tried to summarize the messy layout cycle of ViewController and View
Tutorial to create a blog with Rails for beginners Part 1
I tried to collect and solve Ruby's "class" related problems.
[For Ruby beginners] Explain how to freely delete array elements!
How to transform ARKit and SceneKit shapes with Metal shader
How to use Font Awesome icon for ul and li
How to test a private method with RSpec for yourself
How to solve the problems of Java's three Blocking Queues
Tutorial to create a blog with Rails for beginners Part 2
Procedures for passing RealmObject to Fragment and how to use Parceler
For Java beginners: List, Map, Iterator / Array ... How to convert?
[Xcode] How to arrange Xcode and Simulator screens in full screen
Investigated how to call services with Watson SDK for Java
How to create and launch a Dockerfile for Payara Micro
Tutorial to create a blog with Rails for beginners Part 0
How to deal with different versions of rbenv and Ruby
[Rails] How to display error messages for comment function (for beginners)
How to change the file name with Xcode (Refactor Rename)
Solve Google problems with Ruby
[Swift] How to use UserDefaults
How to use Swift UIScrollView
How to number (number) with html.erb
How to update with activerecord-import
[For super beginners] The minimum knowledge you want to keep in mind with hashes and symbols
[For beginners] Here are some references related to technology and career.
How to use \ t Escape sequences different for mac and Windows-java
A tool to generate Retina images for iOS for use with Xcode
[RSpec on Rails] How to write test code for beginners by beginners
[Swift] Create a project with Xcode (ver 12.1) and display "Hello, World!"