iOS6、7、8、9新特性总汇和适配说明 (8)

- (BOOL)saveCredentials:(NSError **)error {

    SSKeychainQuery *query = [[SSKeychainQuery alloc] init];

    query.password = @"MySecretPassword";

    query.service = @"MyAwesomeService";

    query.account = @"John Doe";

    query.synchronizable = YES;

    return [query save:&error];

}

 

- (NSString *)savedPassword:(NSError **)error {

    SSKeychainQuery *query = [[SSKeychainQuery alloc] init];

    query.service = @"MyAwesomeService";

    query.account = @"John Doe";

    query.synchronizable = YES;

    query.password = nil;

    if ([query fetch:&error]) {

        return query.password;

    }

    return nil;

}

 

[Format Time: 0.0060 seconds]

不要忘记CocoaPods是快速便捷安装SSKeychian的好方法。

十四、使用NSAttributedString显示HTML

在app中使用webview有时会让人非常沮丧,即使只是显示少量的HTMLneirong ,webview也会消耗大量的内存。现在iOS7让这些变得简单了,你可以从用少量代码在HTML文件中创建一个NSAttributedString,比如:

Crayon Syntax Highlighter v2.7.1

NSString *html = @"<bold>Wow!</bold> Now <em>iOS</em> can create <h3>NSAttributedString</h3> from HTMLs!";

NSDictionary *options = @{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType};

 

NSAttributedString *attrString = [[NSAttributedString alloc] initWithData:[html dataUsingEncoding:NSUTF8StringEncoding] options:options documentAttributes:nil error:nil];

1

2

3

4

 

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zwgywp.html