TechBuzzPro

iOS Code Not Showing: How to Move It Correctly

· 4 min read · Phones & Tablets

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

No, you cannot make code that isn’t part of the iOS target magically appear; you must add the source files to the target and ensure any UI connections are correctly linked.

What You'll Need

  • A Mac running the latest stable version of Xcode.
  • An existing iOS project or a new project where you want the code to live.
  • The source files (Swift, Objective‑C, storyboard, or SwiftUI view) that are currently missing.
  • Basic familiarity with Xcode’s Project Navigator and Build Settings.

Step-by-Step

  1. Open your iOS project in Xcode. If the project is stored in a version‑control system, make sure you have the latest commit checked out.
  2. Locate the missing source files in Finder. If they are outside the project folder, copy them into a logical folder inside the project directory (for example, Sources/ or Views/).
  3. In Xcode, select the Project Navigator (⌘1). Right‑click the group where you want the files to appear and choose Add Files to "YourProject"…. In the dialog, navigate to the files you just copied, select them, and click Add. Make sure the checkbox Copy items if needed is ticked so Xcode creates a managed copy.
  4. When the Add Files dialog appears, you will see a section titled Add to targets. Check the box for the iOS app target you are building. If you have multiple targets (e.g., a test target or an extension), only select the ones that need the code.
  5. Verify that the files are now listed under the target’s Build Phases → Compile Sources. Open the project settings, select the target, go to the Build Phases tab, and scroll to Compile Sources. If any file is missing, drag it from the Project Navigator into this list.
  6. If the missing code is a UI component defined in a storyboard or XIB, open the storyboard file and confirm that the view controller’s class is set to the newly added Swift/Objective‑C class. Select the view controller, open the Identity Inspector, and type the class name exactly as it appears in the source file.
  7. For SwiftUI views, ensure the view is referenced from a parent view or from the App struct. Add an import statement if the view resides in a different module, and call the view in the appropriate place (for example, MyNewView() inside the body of another view).
  8. Check any @IBOutlet or @IBAction connections. Open the storyboard or XIB, right‑click the UI element, and verify that the connection points to the correct class and property name. If Xcode shows a warning icon, click it and choose Connect to re‑establish the link.
  9. Clean the build folder to remove stale caches: choose Product > Clean Build Folder (⇧⌘K). This forces Xcode to re‑compile everything with the newly added files.
  10. Build and run the app on a simulator or device. If the code appears as expected, you have successfully moved it into the iOS target.

Common Mistakes

Skipping the Add to targets checkbox is the most frequent error; the file will be visible in the navigator but never compiled, resulting in “symbol not found” errors. Forgetting to update the storyboard’s class name leaves the UI controller without a backing class, causing runtime crashes. Adding files without checking Copy items if needed can lead to broken references if the original folder is moved or deleted.

Tips

Use Xcode’s File > New > Group to keep related files together; this makes future maintenance easier. Enable Show Live Issues (⌥⌘ L) to see compile‑time problems as you type. When working with Swift packages, add the package to the target via File > Add Packages instead of copying files manually.

Troubleshooting

  1. Restart Xcode. A simple restart clears temporary UI glitches that sometimes hide newly added files.
  2. Confirm that the file’s target membership is still selected. Open the file inspector (⌥⌘1) and look under Target Membership.
  3. Check the build log for “file not found” or “undefined symbol” messages. These usually indicate a missing target membership or a typo in the class name.
  4. If the UI still does not appear, open the storyboard, select the view controller, and click the Resolve Auto Layout Issues button to ensure constraints are not causing the view to be off‑screen.
  5. Delete the app from the simulator or device and reinstall it. Cached data can sometimes prevent new UI elements from loading.
  6. As a last resort, delete the DerivedData folder (~/Library/Developer/Xcode/DerivedData) and rebuild. This removes all intermediate build artifacts.

Frequently Asked Questions

Why does Xcode show my file but the app can’t find the class?

The file is likely not added to the target’s Compile Sources phase, so it never gets compiled into the binary.

Can I move code from an Android project to an iOS project?

No, Android Java/Kotlin code cannot run on iOS. You must rewrite the logic in Swift or Objective‑C, or use a cross‑platform framework.

What if the storyboard shows a warning after I add the class?

Open the Identity Inspector, re‑enter the class name, and reconnect any @IBOutlet or @IBAction connections that show a broken link.

Is cleaning the build folder enough to fix “module not found” errors?

Often, but you also need to verify that the file’s target membership and import statements are correct.

Do I need to update the app’s Info.plist when adding new view controllers?

Only if the new view controller uses a custom URL scheme or requires special permissions; otherwise the plist remains unchanged.