nsstring

Objective-C 101 (retain vs assign) NSString

感情迁移 提交于 2019-12-28 01:43:06
问题 A 101 question Let's say i'm making database of cars and each car object is defined as: #import <UIKit/UIKit.h> @interface Car:NSObject{ NSString *name; } @property(nonatomic, retain) NSString *name; Why is it @property(nonatomic, retain) NSString *name; and not @property(nonatomic, assign) NSString *name; ? I understand that assign will not increment the reference counter as retain will do. But why use retain , since name is a member of the todo object the scope of it is to itself. No other

iOS开发之支付宝集成

一笑奈何 提交于 2019-12-28 00:41:13
项目中要用到支付功能,需要支付宝,微信,银联三大支付,所以打算总结一下,写两篇文章,方便以后的查阅, 大家在做的时候也能稍微参考下,用到的地方避免再次被坑。这是第二篇支付宝集成,第一篇银联支付 在这里 。本来要用那个ping++的神器,可以集成各种支付手段,异常的方便,但是考虑到安全性问题的话,支付的渠道还是不让第三方参与的好,不然会不安全,于是就苦逼地慢慢的一个一个集成了。。。。这里就代理支付宝的集成过程: 刚开始以为支付宝集成还是比较简单的,看了几个文章,网上的各位大神也是各种秀操作,说集成很简单,但是,真正做起来就不是那回事了, 特别是新版的1月11号更新的,我正好是这一天开始看的,网上的经验什么的 大都是比较老的,比较新的能用到的文章不多(但是好文章还是有的,对我帮助也很大),现在我就来一步一步说一下自己集成支付宝的血泪史! 下载支付宝SDK 首先是开发包下载,还是比较难发现的,网上以前文章中的链接都打不开,我找了好久才找到的。 最新的地址在这里 (注意的是下载出来的SDK包里面并没有传说中的开发文档,需要其他地方找或者看网页上的)。 公钥、私钥、PID、sellerID、key这些东西的用途和获取方式在文档上都有详细的说明,这里不再赘述,一定要把概念分清楚再去做,不然一会就乱了。如果遇到问题的话咱们可以再一起探讨。 支付流程理解 开发文档、开发文档、开发文档

iOS支付宝支付集成

爷,独闯天下 提交于 2019-12-28 00:40:53
概述 iOS支付宝支付集成 详细 代码下载: http://www.demodashi.com/demo/10729.html 支付宝和微信都是业界的老大哥,相信大家都有所觉得文档、SDK都是各种坑吧(纯粹吐槽而已),本文先整理支付宝支付集成。 一、准备工作 1、向支付宝”签约" 成为支付宝的”商户”, 签约完成后, 支付宝会提供一些必要的数据给我们(商户ID-partner,帐号ID-支付宝帐号) 注意:签约成为支付宝商户,需要提供公司营业执照[ http://act.life.alipay.com/shopping/before/help/index.html](http://act.life.alipay.com/shopping/before/help/index.html ) 2、获取支付相关的 '私钥' 和 '密钥' [ https://doc.open.alipay.com/doc2/detail?treeId=44&articleId=103242&docType=1 ]( https://doc.open.alipay.com/doc2/detail?treeId=44&articleId=103242&docType=1 ) 3、下载支付的SDK [ https://doc.open.alipay.com/doc2/detail?treeId=54

iOS标准时间与时间戳相互转换

半城伤御伤魂 提交于 2019-12-27 21:01:09
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 设置时间显示格式: NSString* timeStr = @"2011-01-26 17:40:50"; NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] autorelease]; [formatter setDateStyle:NSDateFormatterMediumStyle]; [formatter setTimeStyle:NSDateFormatterShortStyle]; [formatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"]; // ----------设置你想要的格式,hh与HH的区别:分别表示12小时制,24小时制 //设置时区,这个对于时间的处理有时很重要 //例如你在国内发布信息,用户在国外的另一个时区,你想让用户看到正确的发布时间就得注意时区设置,时间的换算. //例如你发布的时间为2010-01-26 17:40:50,那么在英国爱尔兰那边用户看到的时间应该是多少呢? //他们与我们有7个小时的时差,所以他们那还没到这个时间呢...那就是把未来的事做了 NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@

NSString: isEqual vs. isEqualToString

南楼画角 提交于 2019-12-27 17:06:54
问题 What is the difference between isEqual: and isEqualToString: ? Why are classes adding isEqualTo* methods (isEqualToArray for NSArray, isEqualToData for NSData, ...) instead of just overriding isEqual: ? 回答1: isEqual: compares a string to an object, and will return NO if the object is not a string. isEqualToString: is faster if you know both objects are strings, as the documentation states: Special Considerations When you know both objects are strings, this method is a faster way to check

How to add commas to number every 3 digits in Objective C?

大兔子大兔子 提交于 2019-12-27 16:39:28
问题 If I have a number int aNum = 2000000 how do I format this so that I can display it as the NSString 2,000,000? 回答1: Don't do your own number formatting. You will almost certainly not get all the edge cases right or correctly handle all possible locales. Use the NSNumberFormatter for formatting numeric data to a localized string representation. You would use the NSNumberFormatter instance method -setGroupingSeparator: to set the grouping separator to @"," (or better yet [[NSLocale

Objective-C: Find numbers in string

梦想的初衷 提交于 2019-12-27 12:18:50
问题 I have a string that contains words as well as a number. How can I extract that number from the string? NSString *str = @"This is my string. #1234"; I would like to be able to strip out 1234 as an int. The string will have different numbers and words each time I search it. Ideas? 回答1: Here's an NSScanner based solution: // Input NSString *originalString = @"This is my string. #1234"; // Intermediate NSString *numberString; NSScanner *scanner = [NSScanner scannerWithString:originalString];

Objective-C: Find numbers in string

旧时模样 提交于 2019-12-27 12:18:04
问题 I have a string that contains words as well as a number. How can I extract that number from the string? NSString *str = @"This is my string. #1234"; I would like to be able to strip out 1234 as an int. The string will have different numbers and words each time I search it. Ideas? 回答1: Here's an NSScanner based solution: // Input NSString *originalString = @"This is my string. #1234"; // Intermediate NSString *numberString; NSScanner *scanner = [NSScanner scannerWithString:originalString];

Any way to bold part of a NSString?

会有一股神秘感。 提交于 2019-12-27 10:39:16
问题 Is there any way to bold only part of a string? For example: Approximate Distance: 120m away Thanks! 回答1: What you could do is use an NSAttributedString. NSString *boldFontName = [[UIFont boldSystemFontOfSize:12] fontName]; NSString *yourString = ...; NSRange boldedRange = NSMakeRange(22, 4); NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:yourString]; [attrString beginEditing]; [attrString addAttribute:kCTFontAttributeName value:boldFontName range

[iOS面试] 理解 copy

牧云@^-^@ 提交于 2019-12-27 05:27:02
前言 NSObject 有 copy 和 mutableCopy 两个成员。这两个函数是分别直接返回 copyWithZone 和 mutableCopyWithZone 的返回值。 因此,如果调用者没有实现 copyWithZone 或 mutableCopyWithZone,肯定会报错:unrecognized selector。 这两个函数,就分别是 NSCopying,NSMutableCopying 协议的成员。 (注意,不是这个: + (id)copyWithZone:(struct _NSZone *)zone OBJC_ARC_UNAVAILABLE; 这个是 MRC 项目可用,ARC 下直接无视该函数,涉及到 Zone 都用 null) 基础框架里的类,很多都实现了 NSCopying,NSMutableCopying,例如 NSString 可以调用 copy 而不报错。那么,这些基础框架是具体怎么实现的这两个协议,才导致了所谓的 “深浅拷贝” ?数组的 [[NSArray alloc] initWithArray: copyItems: ] 到底是干什么的? strong 与 copy 到底用哪个?这些是本文将要回答的。 copy 和 mutableCopy 不可变对象的 copy:指针复制 指针到底是什么?指针本质上是一个 size_t 大小的一个数