zoukankan      html  css  js  c++  java
  • Xcode

    在线安装下载地址 https://developer.apple.com/xcode/index.php

       下载地址 登录进入 connect.apple.com,就可以看到下载列表


    1. 编译时找不到源文件

    编译项目时常报如  Undefined symbols:
    ".objc_class_name_PlacardView", referenced from:
    literal-pointer@__OBJC@__cls_refs@PlacardView in MoveMe2View.o
    ld: symbol(s) not found
    collect2: ld returned 1 exit status

    解决方法参考下文:

    That has happened to me a lot of times. That error is caused when the compiler can't find a class or function. Besides the obvious reasons for that to happen, you should also do something like this:
    On the left of the Xcode window go to the targets, and find your application. Open it. You should see a build phase named "Compile Sources". Make sure that your implementation file is included inside that build phase. If not, drag and drop it onto that build phase.
    Also, make sure that you have all frameworks included and linked to your application! To make that sure, go into your application target again, and see the "Link Binary With Libraries" build phase. See if all necessary .framework files are in there. If not, add them using drag and drop.

    在项目的Groups&Files窗口中,打开Targets/项目名 /Compile Sources/把提示找不到的源文件拖到这里.重新编译.

     

    2.接上手机(版本 4.2.1 8c148a),在Organizer中,报The version of iOS  ...  does not match any of the versions of iOS supported...,重启手机,xcode都不能解决。最后,重装xcode_3.2.5_and_ios_sdk_4.2_final.dmg。

     

    3.设置字体大小:

    1)打开Preferences,快捷键是“Command +,”(注意,是三个键,按住command键,然后再快速地按“+”和“,”两个键即可)

    2)选择“Fonts &Colors”,选中所有的“Category”,然后双击“Font”一列,在弹出的对话框中选择适合自己的字体大小即可。


    4.重构

    包括重构变量名,方法名,和类名。

    选择变量名,点击EditRefactorRename...,要在输入框内输入新名字后,点Preview,然后Preview变成Apply,点击Apply。

    http://blog.csdn.net/f520131480315/article/details/6457927


    5.快照

        一般在开始重构之前要备份,选择File-Make Snapshot,Xcode会记住项目当前的状态。如果发现代码被改得面目全非,选择File-Snapshot,回到做快照的那一刻。

    如果发现提示:Snapshot Failed:A project snapshot cannot be created. 可能是一个磁盘镜像文件被损坏了,它用来存储快照,可以到~/Library/Application Support/Developer/Shared/SnapshotRepository.sparseimage 把镜像文件删掉,然后重启xcode。

        如果发现修改了某些代码之后出了问题,利用 Xcode 快照(snapshot)功能就可以轻松恢复工程到之前的状态,甚至已删除的工程也可以。快照会保存当前工程的所有状态到磁盘上,以备之后进行恢复。Xcode 的工程管理器中列出了所有可用的快照。

        可以随时手动创建快照,也可以让 Xcode 根据场合自动创建快照,例如每次构建之前或通过查找并替换修改代码之前等。

         File > Create Snapshot,输入此快照的名称和描述,点按 Create Snapshot。
此快照就会出现在工程管理器中了。要恢复到此快照,请点选 File > Restore Snapshot。


    6.helpsearch

     用来查找在菜单中的功能,命令等。

     

    7.在svn上增加目录时,用import.

     

    8. 修改某个文件时,弹出

    This file is not writable. You could either perform an SCM Edit operation on this file, or allow editing anyway. You may not be able to save your changes, but you will be able to Save a Copy somewhere else.

    是由于在本地锁定了文件,显示简介 ,去掉勾选已锁定。

     

    9. 制表符替换成2个空格,在编写程序代码时用空格代替Tab,可以避免由于编辑器对tab显示方式不同引起的代码错乱,是一种良好的编程风格

    Xcode Preferences->Indentation 把indent width设置为2个空格。


    10.格式化代码

        Edit - Format->Re-Indent

       在XcodePreferences... key bindings拷贝一份xcode default编辑Re-Indent 同时按下想要设置的快捷键。


       In Xcode 4, it's been moved to Editor (注意是Editor,不是Edit)> Structure > Re-Indent command (and has a default shortcut of CTRL+I ),默认快捷键是 Ctrl加i。它好按且未与其它快捷键冲突,所以不需要修改。


    11.打不开工程文件时,打开project.pbxproj,查找冲突mine,删除冲突标记。


    12.换过证书,提示provising文件问题,在 project.pbxproj 中查找提示那串码,删除掉这串码保存。

     

    13.xcode 4.2 svn问题

        在Respotitories中选中工程目录后,点update,弹出对话框,"Error validating server certificate for  googlecode.com:443.......",解决办法:

        比如用浏览器登录 http://code.google.com/p/.../source/checkout,复制 svn checkout https://xxx.googlecode.com/svn/trunk/ xxx --username xxx,到控制台中运行,提示Error validating server certificate for 'https://xxx.googlecode.com:443':
     - The certificate is not issued by a trusted authority. Use the
       fingerprint to validate the certificate manually!
    Certificate information:
     - Hostname: *.googlecode.com
     - Valid: from Wed, 11 Apr 2012 00:04:01 GMT until Thu, 11 Apr 2013 00:14:01 GMT
     - Issuer: Google Inc, US
     - Fingerprint: cb:f1:c8:ac:28:d5:61:b7:c1:9c:73:7e:3a:b6:bb:e2:e6:55:95:2a
    (R)eject, accept (t)emporarily or accept (p)ermanently?  输入p,开始checkout,然后到xcode中,发现也可以成功执行更新了。


      但在提交上,仍然弹出  Authentication realm: <https://xxx.googlecode.com:443> Google Code Subversion Repository
    Password for '用户名': 
    Authentication realm: <https://xxx.googlecode.com:443> Google Code Subversion Repository
    Username: svn: Commit failed (details follow):
    svn: MKACTIVITY of '/svn/!svn/act/19511c13-1823-4c4e-a551-3e0dfd8c0510': authorization failed: Could not authenticate to server: rejected Basic challenge (https://xxx.googlecode.com)


    14.在xcode4.2中,

          Product -> Profile 再选择leaks,启用内存泄漏监测。

          相比之下,Product Analyze 是更好的工具,它分析一些垃圾代码,及潜在的内存泄漏,并且指出精确的代码行。可以看出,它建议所有自定义函数都返回自动释放的对象,否则会被列入潜在的内存泄漏中,potential leaks。

        添加framework,

    1. In the project navigator, selectyour project 
    2. Select your target
    3. Select the 'Build Phases' tab
    4. Open 'Link Binaries With Libraries'expander
    5. Click the '+' button
    6. Select your framework
    7. (optional) Drag and drop the addedframework to the 'Frameworks' group

          且在xcode4中新建工程时,去掉Use storyboards,Use ARC,include Unit Tests三个复选。


    15.  编译可执行文件时,报object file format invalid or unsuitable

           打开终端:

           sudo su 

           查看/usr/bin目录下是否存在codesign_allocate程序,如果存在,执行改名操作
           sudo mv /usr/bin/codesign_allocate /usr/bin/codesign_allocate_old

           将xcode目录下的codesign做一个软链接
           sudo ln -s /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/codesign_allocate /usr/bin


    16. 真机调试时,提示 No provisioned IOS devices are available.Connect an IOS device or choose an IOS simulator as the destination.

          修改IOS Deployment Target,不要高于真机的版本。

    http://rainbird.blog.51cto.com/211214/646828


    17.添加预定义宏

        打开工程 Project--->Edit Project Editting(选着build)选项--->找到GCC Preprocessing->Preprocessor Macros ,例如设置其值为DEBUG=1


    18.xcode4中修改编译生成文件的位置

       Fileproject settingsDerived data location,选择Project-relative,输入文件夹名字


    19. 真机调试报 error: failed to launch '/Users/gzty1/Library/Developer/Xcode/DerivedData/应用名-chiobhpmbvwnqudfqnfawdzjrtey/Build/Products/Debug-iphoneos/应用名.app/应用名' -- No such file or directory (/Users/gzty1/Library/Developer/Xcode/DerivedData/应用名-chiobhpmbvwnqudfqnfawdzjrtey/Build/Products/Debug-iphoneos/应用名.app/应用名)

         出现的原因可能是正在从appstore上安装此程序,同时又在真机调试安装些程序,导致后面真机调试安装此程序一直失败。

         解决方法:重新完成从appstore上安装此程序后,再尝试真机调试安装。

     

    20. Xcode 提供了一系列用来管理整个开发流程的工具,从创建应用到测试、优化应用,直至上传应用到 App Store。

          http://www.guomii.com/posts/20273

          原英文版地址

          https://developer.apple.com/library/ios/#referencelibrary/GettingStarted/RoadMapiOS/Tools/CreateYourAppinXcode/StartYourProjectinXcode/StartYourProjectinXcode.html

          本《iOS应用开发入门指南》译自苹果官方的 Start Developing iOS Apps Today 系列教程。

          http://www.guomii.com/posts/20250


          Provisioning Portal 配置门户

          在创建新工程向导中,Class Prefix,应用委托就会被命名为 [Class Prefix]AppDelegate


    21.Storyboards,故事板

         故事板里包含了定义此应用程序用户界面的对象、过渡(Transition)以及连接(Connection)。查看源文件发现MainStoryboard.storyboard是xml格式的内容。

         http://www.guomii.com/posts/20868

         利用 Xcode 检视器(Inspector),来观察视图控制器的状态等信息。

         需要注意的是,当选择一个视图时 Xcode 会将其高亮显示,此时画布中的颜色因为叠加可能会和 Colors 窗口中所选的颜色不完全一致。

         对齐引导线,它们能帮你轻松在视图中将 UI 元素对齐到边界或中心位


    22.IBActionOutlet

        在 Xcode 中,给某个 UI 元素添加动作并设定相应的动作方法的途径是:按住 Control 键,并从画布上的该元素拖动到合适的源文件上(一般而言就是视图控制器的源文件)。故事板会把通过这种方式建立的连接进行存档。之后,当应用运行载入故事板时,这些连接就会被还原出来。

       在 Xcode 工具条里,点按 Utilities(实用工具)按钮关闭实用工具区域,然后点按辅助编辑器按钮(Assistant Editor)调出辅助编辑器面板。
    确保辅助编辑器里显示的是视图控制器的头文件。在画布中,按住 Control 并从 Hello 按钮拖动到 HelloWorldViewController.h 的方法声明部分(即 @interface 语句到 @end 语句之间的部分)。

       在非苹果键盘上control键依然是Ctrl键。
       IBAction 是一个特殊的关键词,用来告诉 Xcode 把一个方法当成目标-动作连接来看待。IBAction 被定义为 void

       插座变量(Outlet)描述的是两个对象之间的连接。当你需要让一个对象(例如视图控制器),与它所包含的一个对象(例如文本框)进行沟通时,你就会把被包含的那个对象称为插座变量。当应用运行起来时,你在 Xcode 里创建的插座变量就被还原出来了,这样在运行时这些对象就可以相互交流了。

       给文本框设置委托对象:按住 Control 键并从文本框拖动到场景坞里的黄色球体上(黄色球体代表视图控制器对象),当半透明面板出现时,选择 Outlets(插座变量)部分的delegate


    23.源代码控制管理(SCM)

         能够提供比快照更加细致入微的变更跟踪管理。(如果你在团队中与他人协同工作,源代码控制管理还能帮你提高团队效率。)SCM 系统会在磁盘中对每个文件保存多个版本,并存储各个文件各个版本的元数据到 SCM 仓库中。

         Xcode 支持两种流行的 SCM 系统:Git 和 Subversion。Xcode 包含了一个版本编辑器,无论使用哪种 SCM 系统都可以轻松对比保存在仓库中文件的不同版本。如果你发现代码中出现了漏洞,则可以将最新的版本和之前的某个正常运行的版本拿来比较,让你捉出产生问题的“臭虫”。




    24.分发和发布应用
         Xcode 能够让你轻松地将尚未正式发布到 App Store 的应用分享给测试者们。要分发应用,请在方案编辑器中创建一个应用归档。然后就可以使用 Xcode 的归档管理器来让测试者们分享你的应用。

         当你准备正式发布应用的时候,可以先使用归档管理器来评估一下你的应用能否达到 App Store 审核的标准。这项评估能够通过则可以保障正式审核过程尽可能地快速。然后就可以在 Xcode 正式向 App Store 提交你的应用了。


    学习进度

    http://www.guomii.com/posts/20284


    25.在instruments中查看内存

         

    The Living bytes, or Net bytes is how much memory your application is using at the time you select in the timeline. That will include leaked memory, since leaked memory is never deallocated.

    #Living is how many allocations of a certain size/object type happened (and are still allocated). This is very useful when looking for leaks. For example, if you repetitively perform an action (like coming in an out of a modal view controller), and you see that #Living of an object grows by the same amount each time, then you're probably leaking those objects. You can then confirm by drilling down and seeing the exact line of code that is allocating the objects, and even see the time index each one was created.

    Overall bytes includes memory that has been released. It's useful to track that number for performance optimization purposes, but not if you're just trying to see your current memory footprint or look for leaks.


    笔画输入面板打开后,内存使用增加了20M


    苹果bug--获取键盘有内存泄露问题
    memory leaks in open_handle_to_dylib_path and UIKeyboardInputManagerClassForInputMode
    If you're developing an iPhone app that uses UITextField objects and you're rigorous enough to check for memory leaks using Instruments, chances are you'd discover some leaks in UIKit and CoreGraphics libraries, stemming from some allocations done in dyld::mkstringf, called from dyld::loadPhase5.
    According to some reports found on the web, it seems that this is a bug in the tools from Apple, and it appears only on the simulator, not when testing on the actual device. So you could safely ignore it. In any case you couldn't do anything about it, as the traceback leading to the leak goes through code outside of your control, that is, unless you happen to work for Apple :).


    26.安装后可以看到还有一个dashcode,它用于web开发


    27. 如果工程中的代码失去了着色,到Users/gzty1/Library/Developer/Xcode/DerivedData删除对应目录,再重新编译即可。

          products目录生成的文件在 /Users/gzty1/Library/Developer/Xcode/DerivedData中,可以在Preferences/Locations中找到。

     

    28.资源文件夹管理

         http://blog.csdn.net/bl1988530/article/details/7161387

         xcode里的新建的一个分组文件夹(黄色的),并不是真正在目录下就有一个这样的文件夹。然而有时候项目要用到的资源很多,有时候还会有重名的情况,这样如果放在分组文件夹里就不好了。

        为了方便管理,在目录下新建一些真实存在的文件夹来存放这些资源,然后把这个文件夹加入到xcode的时候不要选copy items into destination group's folder,而Folders那一项要勾选create folder references for any added folders,这样文件夹加入进去就是蓝色的,真实存在的。

        NSString *themePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@“theme”];//actual theme path
    if(themePath)
    self.backgroundIV.image = [UIImage imageWithContentsOfFile:[themePath stringByAppendingPathComponent:@"mask_1.png"]


    29.工程中的.js文件可能在生成包中未找到,是因为它被当作了代码文件,未被当作资源文件。

         在build phases中处理...

         同时可以看出,在UIWebView中,可以使用<script src="a.js”>来使用js文件。


    30.Xcode 的 Groups&Files 边栏看起来像 Finder 里的文件夹和文件。但是它和 Finder 里的文件夹是两个不同 的概念。可以在 Xcode 里面随意安排群组,但是这些文件在 Finder 面还是在同一个文件夹里面。这就是为什么称它们为群组:可以在 Xcode 里任意地安排文件,而不用理会这些文件到底是存放在硬盘的哪个位置。


    31.预编译前缀头文件 “HelloWorld_prefix.pch”头文件的作用是给编译过程加速。应该把不常变 化的框架(Frameworks)头文件添加到前缀头文件(prefix header)中。这样 的话,在编译的时候,框架的代码会被预先编译,所有的类都将可以使用这些 头文件。不幸的是,这样做也有一个缺点:如果前缀头文件里其中一个头文件 发生了变化,所有代码将会重新编译。这就是为什么应该只添加那些极 少或者从来都不变化的头文件到前缀头文件中。

    例如,把cocos2d.h头文件加到前缀头文件中

    #ifdef __OBJC__

          #import <Foundation/Foundation.h>
    #import <UIKit/UIKit.h>
    #import "cocos2d.h"
    

    #endif


    32.在Apple LLVM compiler 3.1 warnings 中有一个相关的编译器报警设置“Undeclared Selector”设置为YES,可以选择对不存在的@select(...)在编译时报错。


    33. 打包发布

    http://www.cnblogs.com/yaokang/archive/2012/05/29/2524273.html

    http://mobile.51cto.com/iphone-277009.htm


    34.使用OmniGraffle 把工程中的类导出为类关系图;


    35.调试时,在Debug Navigator中,为了看到堆栈的更多信息,拖拽Debug Navigator底部的滑块到最右边。它将会展示出崩溃时全部的堆栈信息,在底部的函数start(),第一个被调用,很多方法是灰色的,是因为他们都来自内置的ios frameworks(ios内置框架),没有可见的源码。

     

    36.profile "" not found

        在project.pbxproj中找那一串,置空、


    37.如何解决Could not launch app - No such file or directory
    升级到XCode4.5后会经常出现“Could not launch app - No such file or directory”这个问题,下面介绍下我的解决方法

    1.断开设备,删除在设备调试的APP
    2.强行退出XCode(Quit xcode),不要只是关闭,直接强行退出
    3.删除系统生成的文件 (~/Library/Developer/Xcode/DerivedData/),使用终端命令进入到相应目录,然后执行:rm -rf DerivedData/,等一会就可以了

       终端输入 cd /Users/用户名/Library/Developer/Xcode  进入DerivedData文件夹的上一层.

       然后输入  rm -rf DerivedData  删除DerivedData文件夹

     4.重启XCode,连接完设备测试就可以了

      ※备注:  (/Users/用户名/Library/Developer/Xcode/DerivedData 这个路径可以在Xcode->Preferences->locations中找到,然后复制) 

  • 相关阅读:
    ORACLE日期时间函数大全
    orcal基础
    javaweb学习总结——基于Servlet+JSP+JavaBean开发模式的用户登录注册
    一个DataTable赋值给另一个DataTable的常用方法
    ios开发 解释器和编译器
    ios面试题(五)-多线程
    ios面试题(四)-block
    ios面试题(三)
    ios开发面试题(二)
    ios开发面试题(一)
  • 原文地址:https://www.cnblogs.com/chengfang/p/claire.html
Copyright © 2011-2022 走看看