iOS 小提示 respondsToSelector
respondsToSelector的大概方法如下:
1 | if ([NSArray respondsToSelector:@selector(arrayWithObjects:)]){ |
就是NSArray是否会执行arrayWithObjects:方法,一般在执行代理函数之前先这样respondsToSelector检测一下。
respondsToSelector的大概方法如下:
1 | if ([NSArray respondsToSelector:@selector(arrayWithObjects:)]){ |
就是NSArray是否会执行arrayWithObjects:方法,一般在执行代理函数之前先这样respondsToSelector检测一下。
The iOS SDK that developers use to build iPhone and iPad apps is relatively low level, requiring the developer to do a lot of work to get their app up and running. Fortunately there are lots of third party libraries available that provide useful functionality that can make your life as an iOS developer much easier. Here we discuss 10 of the best:(阐述IOS库的是很有用的)
MBProgressHUD – Progress Indicator Library(进展指示符库)
Many official Apple apps have a nice translucent progress display. Unfortunately it’s an undocumented API, and therefore using it is likely to get your app rejected from the app store. This library provides a drop in replacement that looks almost identical. It also provides some additional options, such as a visual progress indicator, and a progress completion message. Integrating it into your project is as simple as adding a couple of files, so you’ve got no excuse not to!
ASIHttpRequest – HTTP Network Library(HTTP Network库)
The iPhone’s network API can be a little verbose. the ASI library simplifies network communication greatly, and offers advanced tools such as file uploads, redirect handling, authentication, form submission, and caching. If you’re doing anything HTTP related in your iPhone app then this library will make your life so much easier! Here’s how simple it makes fetching a website asynchronously:
1 | - (void) loadAppDevMag |
JSON Framework – JSON Support(JSON支持)
If your app interacts with any web services you’ll more than likely come across JSON encoded data. Surprisingly there’s no support for JSON in the native iOS libraries, but the JSON framework provides everything you need, including a parser to turn JSON strings into objects, and a generator to create JSON strings from objects. This library is so popular, and JSON so common, that it’s actually included in many of the other libraries features in this post already. Here’s a quick example:
1 | // JSON string -> NSDictionary |
Flurry – Detailed Usage Statistics(详尽的使用统计)
By adding the flurry SDK to your project you’ll automatically get a load of usage statistics about your application, such as how many users you have, how active they are, and where they are in the world. The real power of flurry though is that it allows you to specify your own events to track, and log errors. All of this information is then available in a Google Analytics style dashboard, so you can see what your users are doing with your app, and what problems they’re running into. You really should be using some kind of usage tracking library, and although alternatives do exist, such as Google Analytics for Mobile and Localytics, Flurry has worked really well for me.
RegexKitLite – Regular Expression Support(正则表达式支持)
Regular Expressions are a really powerful tool, and the absence of support for regular expressions in the iPhone SDK seems to be a glaring omission. Fortunately the RexexKitLite library is here to help. It’s a powerful fully featured regex library that’s simple to use. Here’s the sample code to match a phone number:
1 | // finds phone number in format nnn-nnn-nnnn |
Facebook iOS SDK – Facebook API Library(Facebook API 库)
Facebook login (previously called Facebook Connect) is used all over the web as a way for users to login to services by using their existing Facebook account, saving them from having to create lots of separate accounts. This library allows you to do the same with your iPhone apps. It also has full support for both the Facebook Graph API and the older REST api, which give you access to the social graph and related Facebook information of your users, and make it easy to implement features such as friend finders and inviters. This library is used by a lot of big name apps for their Facebook integration, so if you want to use Facebook as your primary authentication method or you’d just like to add a friend invite feature this library is well worth checking out.
SDWebImage – Simple Web Image Support(网络图片支持)
SDWebImage is a library for dealing with images on the web. It allows you to use images on the web as easily as local files already packaged with your application. It automatically handles caching, and also supports advanced features such as placeholder images and a download queue. Once you’ve added it to your project you can set the image for a UIWebView as simply as:
1 | [imageView setImageWithURL:[NSURL URLWithString:@"http://example.com/image.png"]]; |
Similar functionality is provided by the Three20 library, mentioned later, but if you’re after a simple library that focuses on doing one thing well, and you’re using web based images in your project, then SDBWebImage is what you need.
GData client – iPhone library for all of Google’s services(iPhone上所有Google相关服务的类库)
Google’s official GData library allows you to access many of Google’s services, including contacts, calendar, analytics, picasa, translate and YouTube. The project is well documented, and contains lots of example applications. With all of the great services Google offer there are so many different ways that this library could be used to enhance an existing application, and there are probably lots of interesting apps that could be built off the back of the example apps included in this library. If you’re an iOS developer stuck for ideas then this is where I’d suggest you look!
CorePlot – 2D Graph Plotter(2D图形绘图仪)
CorePlot makes makes it extremely easy to visualize your data in a variety of ways, and produces very attractive graphs. It supports bar graphs, pie charts, line graphs, and complex mathematical function plotting among others. The library is well documented, and the website contains lots of examples of where it’s already being used, including stock price applications, game scores, personal finance apps, and for web analytics visualization.
Three20 – General iOS Library(通用iOS库)
The Three20 library came out of the official Facebook iPhone app. It’s a fairly big and full featured library, including low level components such as a HTTP cache, and many higher level UI components such as a photo viewer and web based table view. It can be a little tricky to integrate Three20 into existing projects, but if you’re starting a project from scratch Three20 can really give you a big head start, especially for projects that make heavy use of the web.
Whether it’s interacting with a web API, visualizing data, loading images from the web, or creating social features in your app, the libraries listed here make developing such features easier and less time consuming. If you’re an iOS developer and you haven’t made use of any of these libraries then you should definitely check them out before starting your next project. If you have used any of them, or one that we haven’t mentioned, then please let us know your experiences in the comments.(有了更多的库,会让你的开发更容易,生活更美好)
I got this error after installing nginx and trying to run passenger for my ruby apps. I understood that I needed to run nginx as the same user I was using to run my ruby apps. To do this, I had to use the “user” directive in the nginx.conf file to define the startup user to be “presmini” (the same user running my ruby apps). What I screwed up was that the failure(他也遇到了,其实我也遇到了)
1 | [emerg]: getgrnam(“presmini”) failed in /opt/nginx/conf/nginx.conf:1 |
上面是错误提示的说明。
is that I wasn’t explicity defining a group in the nginx.conf file, and so it was defaulting to something that does exist. Since I’m on a mac, I just changed the “user” directive in the nginx.conf file to:
原因是没有添加组
1 | user presmini staff |
修改成类似这样的就可以了
I’ve been considering diving into nginx for a bit now. Rumors of it’s speed and Cyrillic error messages have intrigued me. With recent forays into node.js apps and their requirement for a free port, I wanted to find a nice solution that complimented the evented speed of node.js without exposing a port publicly for each app. As it turns out Nginx is suited quite nicely to this. But that wasn’t where it ended. I found nginx to have a much more interesting and dynamic config language. And even beyond that it gave me a good excuse to learn more about running PHP as a FastCGI process and how PHP-FPM (baked in as of 5.3.3) fits into the picture. Not sure if MEMP is the correct acronym, but since I’ve seen talk of LEMP servers, I’ll run with it.(似乎说了一下为什么要使用PHP-FPM)
MacPorts. If you’re not already familiar with it, I recommend reading up before proceeding.
Since I already have MySQL set up and configured I won’t bother covering it here. It’s pretty well documented around the webs. The main focus here is going to be getting nginx installed and setting up PHP as a service to it with an emphasis on local development. No need to tweak this for production on my Macbook Pro.(这里说明了一下MacPorts是什么,给他带了什么好处)
PHP 5.3.3 introduced PHP-FPM (FastCGI Process Manager) to the codebase. Building it requires a few extra config flags and generates a php-fpm binary. The binary will manage spawning cgi processes and handling the FastCGI passthru from nginx. Currently MacPorts does not have an option to build PHP with PHP-FPM. After some hacking on the current Portfile I arrived at a working solution. It includes the correct flags, a dependency on libevent, and a startup item.(这里介绍了一下什么是PHP-FPM)
First things first.
1 | sudo port selfupdate |
(If you’ve already got the php5 package installed, uninstall it and it’s cohorts to ensure a clean install process going forward.)
This is a bit of a hack and there’s probably a better way, like submitting a proper patch to MacPorts, but this will get the job done for today.
1 | # replace this file with the Portfile from the gist below |
Then run the regular port install.
1 | sudo port install nginx php5 +fastcgi php5-apc php5-mysql +mysqlnd |
Next we’ll need to set up the configs. There’s two basic configs that require attention. First is the nginx config. Since this is just for a local development env we can be pretty lean on what we need.
下面是关于nginx的配置
1 | # /opt/local/etc/nginx/nginx.conf |
This is the config that I’m currently using as my generic site config. It has a few nice features. First the server name is matched against a regular expression. So any site that matches local.xxxx.com will be parsed and use the xxxx as a sub-directory in my Sites folder. This is nice. So I only need to create a new directory and add my local.xxxx.com domain to /etc/hosts pointed at 127.0.0.1 and I can immediately begin developing. Gone are the days of creating a new v-hosts file, enabling it, and restarting apache every time I want to play with a new site’s code. The other nicety here is we’re using a unix socket for the fastcgi passthru. This is unnoticeably faster on my Mac, but again frees up the need to be concerned with another open port on my system.
It’s worth noting that any fastcgi_param that you define in this config is available within PHP as a $_SERVER variable.
The second config is the FPM config. Copy /opt/local/etc/php-fpm.conf.default to /opt/local/etc/php-fpm.conf and open it up. Here are the important ones to modify:(下面是关于php-fpm的配置)
1 | pid = /opt/local/var/run/php-fpm.pid |
It’s pretty straight-forward. Lean cus we can. Save and continue.
At this point we’ve got all the pieces in place. We just need a way to start/stop/restart nginx and FPM. I looked for a cleaner way to accomplish this but in the end it came down to a handful of aliases. Add these to your ~/.profile.(配置啊启动和关闭nginx,fpm)
1 | # nginx |
(到这里,果然牛逼,直接放在自己的命令行里面)
Reopen the Terminal window to enable the new aliases. Start or restart nginx and FPM as the case may be.
At this point you should be able to create a site directory, add a domain to /etc/hosts and drop in an index.php with phpinfo(); to verify that PHP is working.
Hopefully this will be of some use to other aspiring MEMP devs out there.
来源:http://blog.jasonmooberry.com/2010/12/memp-php-5-3-with-fpm-and-nginx-via-macports/
—先安装XCode,这样才有GCC等必要开发工具包
默认XCode安装完成不会添加命令行支持,需要在XCode的“偏好设置–>下载–>选择下载命令行支持”
–命令行在 “应用程序–> 实用工具–>终端”
建议通过Macports来进行安装,(附MacPorts安装使用说明)。只需要执行如下指令:
1 | sudo port install pcre |
如果你已经通过自己下载pcre包来make & make install,很有可能会由于安装的pcre路径问题,在安装其他软件时会出问题。想要删除安装好的pcre,则只需要在下载下来的pcre解压文件夹下,执行make uninstall。
方法一:仍然通过Macports,执行下面语句就ok
1 | sudo port install nginx spawn-fcgi |
方法二:
1 | $curl -O http://nginx.org/download/nginx-0.8.53.tar.gz |
配置文件为:/usr/local/nginx/conf/nginx.conf
默认安装在/usr/local/nginx
启动:输入以下命令启动Nginx,然后浏览器输入地址 http://localhost 进行测试,看到很大的字体的Welcome to nginx!就代表安装成功了
1 | /usr/local/nginx/sbin/nginx |
推荐关闭方式:
1 | /usr/local/nginx/sbin/nginx -s stop |
其他关闭方式:
1 | ps -ef | grep nginx # 找到pid |
1 | sudo port install php5 +fastcgi fcgi php5-gd php5-mysql php5-sqlite php5-eaccelerator php5-curl php5-iconv |
1 | cd /opt/local/etc/php5 |
将时区修改为:date.timezone = Asia/Chongqing
错误级别修改为:error\_reporting = E\_ALL & ~E\_NOTICE
启动:
1 | sudo /opt/local/bin/spawn-fcgi -C 2 -p 9000 -f /opt/local/bin/php-cgi |
1、 php.ini(/opt/local/etc/php5/php.ini或者/etc/php5/cgi/php.ini)的配置中这两项
1 | cgi.fix_pathinfo=1 (这个是自己添加的) |
并修改下面:
1 | location ~ \.php$ { |
/var/www/sitepath
部分路径需要根据你主机主目录的实际情况填写,也可以用$document_root代替,其值实为PHP配置文件中的basedir一值。
测试方法:
在nginx的html目录下(默认为/usr/local/nginx/html),新建一个文件test.php,输入以下测试代码:
1 | <?php |
通过http://localhost/test.php 访问,如果能正常显示,那恭喜你,ok了。
附nginx, php, mysql快捷启动代码,建议复制保存为startup.sh,每次通过执行./startup.sh,然后输入管理员密码,就一次性开启了三项服务:
1 | #!/bin/sh |
再附上nginx, php, mysql快捷关闭代码,建议复制保存为shutdown.sh,每次通过执行./shutdown.sh就关闭了三项服务:
1 | #!/bin/sh |
我最近在使用plist存数数据,方便后面的数据浏览
很是苦恼于是自己就查遍各方资料,弄了一个简单的类函数,方便自己的更新数据
1 | #import <Foundation/Foundation.h> |
1 | #import "personIndex.h" |
1 | NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES); |
1 | NSHomeDirectory(); |
1 | NSTemporaryDirectory(); |
1 | [[NSBundle mainBundle] resourcePath]; |
或
1 | [[NSBundle mainBundle] pathForResource: @"info" ofType: @"txt"]; |
来源:http://www.cnblogs.com/kaixuan/archive/2011/05/31/2064796.html
+(id)dictionaryWithObjectsAndKeys:obj1,key1,obj2,key2,……nil
顺序添加对象和键值来创建一个字典,注意结尾是nil
-(id)initWithObjectsAndKeys::obj1,key1,obj2,key2,……nil
初始化一个新分配的字典,顺序添加对象和值,结尾是nil
-(unsigned int)count
返回字典中的记录数
-(NSEnumerator*)keyNSEnumerator
返回字典中的所有键到一个 NSEnumerator 对象
-(NSArray*)keysSortedByValueUsingSelector:(SEL)selector
将字典中所有键按照selector 指定的方法进行排序,并将结果返回
-(NSEnumerator*)objectEnumerator
返回字典中所有的值到一个 NSEnumetator 类型对象
-(id)objectForKey:key
返回指定key 值的对象
+(id)dictionaryWithCapacity:size
创建一个size大小的可变字典
-(id)initWithCapacity:size
初始化一个size 大小的可变字典
-(void)removeAllObjects
删除字典中所有元素
-(void)removeObjectForKey:key
删除字典中key位置的元素
-(void)setObject:obj forKey:key
添加 (key , obj)到字典中去;若key已经存在,则替换值为 obj
最近在搞到,如何解析json文件,使用ios自带的函数很容易解析出来,但是对于中文的问题,一直困扰着我,于是查看了各种相关资料,最后我的解决方法如下:
1,让我找到了一个兼容ARC机制的类库,SBJson,现在地址:https://github.com/stig/json-framework/downloads,最近的一个版本支持ARC
2,将其下载过来后,引入到项目中,#import “SBJson.h”
3,使用方法是
1 | -(void) test{ |
上面只是一个,自己写的json格式的字符串,自己可以使用来自远程获取的数据,做一下测试
所有继承 NSObject 的的对象可以调用isKindOfClass 方法
1 | (BOOL)isKindOfClass:(Class)aClass |
例如:
1 | BOOL test = [obj isKindOfClass:[SomeClass class]]; |