随笔分类 -  Objective-C

摘要:1. 首先,我们快速过一下,什么是Block? Block是一段代码,它在OC中以^开头,可以有返回值,和参数列表,但就是没有名字。 所以,你可以把它认为是匿名函数。 事实上,它和Swift中的闭包(Closure)是一样的。 或者,学过.NET的童鞋知道委托吧,它和委托也差不多概念。 都是可以在一 阅读全文
posted @ 2016-11-18 23:33 Master HaKu 阅读(649) 评论(0) 推荐(0) 编辑
摘要:Objective-C语言的对象类型都必须用指针,对象所占的内存是在堆(heap)上分配的。 NSString也必须在堆上分配,因此必须用指针。 NSString *someString = @"here is the string";NSString *anotherString = someSt 阅读全文
posted @ 2016-11-05 15:20 Master HaKu 阅读(249) 评论(0) 推荐(0) 编辑
摘要:NSString *tempA = @"123"; NSString *tempB = @"456"; 1,字符串拼接 NSString *newString = [NSString stringWithFormat:@"%@%@",tempA,tempB]; 2,字符转int int intStr 阅读全文
posted @ 2016-03-22 09:57 Master HaKu 阅读(21787) 评论(0) 推荐(0) 编辑
摘要:看看下面的程序有什么问题:BNRItem.h@interface BNRItem : NSObject@property (nonatomic, strong) BNRItem *containedItem;@property (nonatomic, strong) BNRItem *contain... 阅读全文
posted @ 2015-04-17 16:39 Master HaKu 阅读(327) 评论(0) 推荐(0) 编辑
摘要:1. 画矩形和写字 2. 射线渐变 3. 居中文字 4. 图片 5. 画布中的画布 阅读全文
posted @ 2014-08-15 11:52 Master HaKu 阅读(469) 评论(0) 推荐(0) 编辑
摘要:以前学过C/C++/Java/C#语言的童鞋可能刚开始对于OC的方法和参数的命名规范大为不爽举例来说,如下一个OC方法:- (void)tableView:(UITableView *)tableViewcommitEditingStyle:(UITableViewCellEditingStyle)... 阅读全文
posted @ 2014-08-14 10:53 Master HaKu 阅读(6645) 评论(0) 推荐(0) 编辑
摘要:我不知道该如何翻译Block这个关键字在Objective-C中,但是可以肯定得是:Block是一段代码。 我们来看它的英文解释: Blocks are a way to define a block of code that you will use at a later time. Someti 阅读全文
posted @ 2014-06-30 11:25 Master HaKu 阅读(208) 评论(0) 推荐(0) 编辑
摘要:1. Loading Data from Files and URLs// Assuming that there is a text file at /Examples/Test.txt:NSString* filePath = @"/Examples/Test.txt";NSData* load... 阅读全文
posted @ 2014-06-05 10:00 Master HaKu 阅读(641) 评论(0) 推荐(0) 编辑
摘要:1. Methods and Messagesa) class method - call it by sending a message to the class itselfb) instance method - call it by sending a message to an instance of the classAn Objective-C method’s name must contain exactly as many colons as the methodtakes parameters, and, the parameter name must end with 阅读全文
posted @ 2013-12-02 14:42 Master HaKu 阅读(208) 评论(0) 推荐(0) 编辑
摘要:#import <Foundation/Foundation.h>// --------------------------------------------------@interface Tire : NSObject@end // Tire@implementation Tire- (NSString *) description{ return (@"I am a tire. I last a while");} // description@end // Tire// ----------------------------------------- 阅读全文
posted @ 2013-04-02 16:43 Master HaKu 阅读(286) 评论(0) 推荐(0) 编辑
摘要:#import <Foundation/Foundation.h>// --------------------------------------------------// constants for the different kinds of shapes and their colorstypedef enum { kRedColor, kGreenColor, kBlueColor} ShapeColor;// --------------------------------------------------// Shape bounding rectangle... 阅读全文
posted @ 2013-04-02 15:44 Master HaKu 阅读(390) 评论(0) 推荐(0) 编辑
摘要:1.In Xcode, choose Product-> Edit Scheme and then click the Arguments tab2As shown in the following screen shot, click the plus sign in the Arguments Passed On Launch section, andtype the launch argument—in this case, the path to the words.txt file 阅读全文
posted @ 2013-04-02 14:31 Master HaKu 阅读(663) 评论(0) 推荐(0) 编辑
摘要:如果学过Java和C#的人,这里容易搞混,Objective-C中的@interface关键字是申明类@interface Circle : NSObject{ @private ShapeColor fillColor; ShapeRect bounds;}- (void) setFillColor: (ShapeColor) fillColor;- (void) setBounds: (ShapeRect) bounds;- (void) draw;@end // Circle如上,这样的申明类的方式确实让我们Java和C#程序员有点不太习惯,连缩进方式也是还是来看一下完... 阅读全文
posted @ 2013-02-20 10:45 Master HaKu 阅读(177) 评论(0) 推荐(0) 编辑
摘要:#import <Foundation/Foundation.h>// --------------------------------------------------// constants for the different kinds of shapes and their colorstypedef enum { kCircle, kRectangle, kOblateSpheroid} ShapeType;typedef enum { kRedColor, kGreenColor, kBlueColor} ShapeColor;// -----... 阅读全文
posted @ 2013-02-20 10:32 Master HaKu 阅读(230) 评论(0) 推荐(0) 编辑
摘要:#import <Foundation/Foundation.h>int main (int argc, const char * argv[]){ FILE *wordFile = fopen ("/tmp/words.txt", "r"); char word[100]; while (fgets(word, 100, wordFile)) { // strip off the trailing \n word[strlen(word) - 1] = '\0'; NSLog (@"%s is %lu charac 阅读全文
posted @ 2013-02-20 10:10 Master HaKu 阅读(329) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示