简体   繁体   中英

Creating New Xcode Project Based On Existing Files. (Creating Laps into an NSTimer)

我是Xcode的新手,我已经为iOS应用创建了一个NSTimer,该应用可以运行,但是我确实需要使用Laptimer扩展此应用,我发现了一个非常好的Laptimer代码,并下载了源代码,但是因为它不是项目,所以只是文件,我不知道如何将.h,.m和.xib文件合并到一个新项目中,因此一切正常。

You can open your project and choose "add files" from the "file" menu (or drag and drop from finder). I'd suggest choosing the option to copy them to your folder, and make sure you have a checkmark next to your project as you're adding the files.

Unfortunately, the process of integrating this new code into your app is a non-trivial exercise and depends entirely upon the particulars of your project, and on the code you're adding to your project.

For example, copying .h and .m files (if the names are unique), is easy. But does your project use NIBs or Storyboards? How about the code you're copying in? How are you going to integrate the user interface files. It's non-trivial and it's hard for us to answer in the abstract.


If you want to create a new project for your LapTimer.xib , LapTimerController.h , LapTimerController.m , UIButton.h , and UIButton.m files, you can:

  1. Create a new project using the "Single View Application" template (make sure to choose not to use storyboards, but you probably want to use automatic reference counting);

  2. Add the five files above to your project (make sure you choose "copy items" to destination folder, as well as have a checkmark next to your app's "target");

  3. Then, presumably, change your AppDelegate.m so that the #import line that says

     #import "ViewController.h" 

    should be changed to says

     #import "LapTimerController.h" 

    Likewise, the line in didFinishLaunchingWithOptions that says:

     self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil]; 

    should say:

     self.viewController = [[LapTimerController alloc] initWithNibName:@"LapTimer" bundle:nil]; 
  4. Try building the app and pray.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM