Dictionary
NSDictionary * dictionary;
dictionary = [NSDictionary dictionaryWithObjectsAndKeys:@"good",@"why",@" bye",@"how",nil];
NSMutableDictionary* dic = [NSMutableDictionary dictionary];
if (spuId) {
[dic setObject:spuId forKey:@"spuId"];
}
if (selectDoctorId) {
[dic setObject:selectDoctorId forKey:@"selectDoctorId"];
}
if (isFirstTreatment ==0 || isFirstTreatment ==1 ) {
[dic setObject:isFirstTreatment? @"true" : @"false" forKey:@"isFirstTreatment"];
}
if (isExpert ==0 || isExpert ==1 ) {
[dic setObject:isExpert? @"true" : @"false" forKey:@"isExpert"];
}
if (gps) {
[dic setObject:gps forKey:@"gps"];
NSEnumerator * enumerator = [dictionary keyEnumerator];
id obj;
while( obj = [enumerator nextObject]) {
NSString* val = [dictionary objectForKey:obj];
NSString* param =(NSString*)obj;
if (val) {
if(![url hasSuffix:@"?"]){
[url appendFormat:@"&"];
}
[url appendFormat:[NSString stringWithFormat:@"%@=%@", param, val]];
}
}
NSArray
NSMutableArray *docList = [NSMutableArray array];
[docList removeAllObjects];
[docList addObjectsFromArray:obj];
元编程
@interface NSString (URLFormat)
- (NSString *)stringByURLFormat:(NSDictionary *)dictionary;
@end
#import "NSString+URLFormat.h"
@implementation NSString (URLFormat)
- (NSString *)stringByURLFormat:(NSMutableDictionary *)dictionary{
if([dictionary count]==0)
return self;
NSMutableString* url = [[NSMutableString alloc] initWithString:self];
[url appendFormat:@"?"];
NSEnumerator * enumerator = [dictionary keyEnumerator];
id obj;
while( obj = [enumerator nextObject]) {
NSString* val = [dictionary objectForKey:obj];
NSString* param =(NSString*)obj;
if (val) {
if(![url hasSuffix:@"?"]){
[url appendFormat:@"&"];
}
[url appendFormat:[NSString stringWithFormat:@"%@=%@", param, val]];
}
}
if([url hasSuffix:@"?"])
[url deleteCharactersInRange:NSMakeRange (url.length-1, 1)];
return url;
}
@end
1、字符串拼接
NSString *newString = [NSString stringWithFormat:@"%@%@",tempA,tempB];
2、字符串转int
int intString = [newString intValue];
3、int转字符串
NSString *stringInt = [NSString stringWithFormat:@"%d",intString];
4、字符串转float
float floatString = [ newString floatValue];
5、float转字符串
NSString *stringFloat = [NSString stringWithFormat:@"%f",intString];
设置颜色
+ (UIColor *)colorWithHexString:(NSString *)stringToConvert alpha:(CGFloat)alpha
{
NSString *cString = [[stringToConvert stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] uppercaseString];
if ([cString length] < 6)
return DEFAULT_VOID_COLOR;
if ([cString hasPrefix:@"#"])
cString = [cString substringFromIndex:1];
if ([cString length] != 6)
return DEFAULT_VOID_COLOR;
NSRange range;
range.location = 0;
range.length = 2;
NSString *rString = [cString substringWithRange:range];
range.location = 2;
NSString *gString = [cString substringWithRange:range];
range.location = 4;
NSString *bString = [cString substringWithRange:range];
unsigned int r, g, b;
[[NSScanner scannerWithString:rString] scanHexInt:&r];
[[NSScanner scannerWithString:gString] scanHexInt:&g];
[[NSScanner scannerWithString:bString] scanHexInt:&b];
return [UIColor colorWithRed:((float) r / 255.0f)
green:((float) g / 255.0f)
blue:((float) b / 255.0f)
alpha:alpha];
}
分享到:
相关推荐
通过学习Objective-C的基本语法、类和对象、控制流程和方法等内容,你将能够编写简单的Objective-C程序并逐渐掌握更复杂的概念。继续学习和实践,你将能够开发各种类型的应用程序,并为用户提供出色的体验。祝你在...
C语言主要知识点巩固(学习Objective-C 的前提),PPT格式。
《Objective-C 程序设计(第4版)》作者假设读者没有面向对象程序语言或者C语言(Objective-C基础)编程经验,因此,初学者和有经验的程序员都可以使用这本《Objective-C 程序设计(第4版)》学习Objective-C。...
用Objective-C语言实现了各种设计模式,收集各种例子,方便大家学习和普及设计模式。.zip用Objective-C语言实现了各种设计模式,收集各种例子,方便大家学习和普及设计模式。.zip用Objective-C语言实现了各种设计...
objective语言快速入门的绝佳途径,是视频教程的完整ppt课件,涵盖所有知识点,后出版书目为《iphone与ipad》开发实战的前半部分语言学习!
Objective-C 基础教程,从入门到精通 Objective-C 基础教程,从入门到精通,是你学习 Objective-C 的经典之作。
elcome to Learn Objective- C on the Mac! This book is designed to teach you the basics of the Objective- C language. Objective- C is a superset of C and is the language used by many (if not most) ...
中文名: Objective-C基础教程 作者: Mark Dalrymple Scott Knaster译者: 高朝勤 杨越 刘霞图书 分类: 软件 资源格式: PDF 版本: 扫描版 出版社: 人民邮电出版社 书号: ISBN: 9787115208774 发行时间: 2009...
在windows系统下搭建Objective-C开发环境,由于公司要做iphone开发,个人学习objc(Objective-C)语法,所以在windows7下搭建了一个objc开发环境,现把自己整理的帮助文档拿来与大家分享,希望能对大家有所帮助。...
objective-c基础学习 资料 适合初学者学习使用
Effective Objective-C是本学习Objective-C的好书,没有见pdf版,亚马逊上的这儿本书的价格不菲。让我们来看看书里的内容和完整的学习笔记吧。
Objective-C与Objective-C++的混用代码示例 可以学习学习
MAC SocketServer Objective-C语言编写 供大家学习
非常全面的Objective-c的学习教程,里面包含了很多程序员的学习笔记有图文解说,还有语法解说,还有使用函数以及如何创建,不管你是新手还是高手都是你Objective-c开发的好工具好帮手,里面还包含了学习网站的教学...
主要说明MacOS App程序如何添加到自动开机启动,使用Objective-C /Swift代码例程,供大家学习
Objective-C 基础语法学习项目
Objective-C 是一种面向对象的编程语言,它建立在C语言的基础上,并且加入了面向对象的特性。Objective-C 通常与苹果公司的操作系统(如 macOS 和 iOS)联系在一起,因为它是这些系统的主要开发语言之一。本指南将...
iOS学习Objective-C基础,非常适合要转行学习iOS的同学