Skip to content

Instantly share code, notes, and snippets.

张嘉夫 josephchang10

Block or report user

Report or block josephchang10

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@josephchang10
josephchang10 / ItemStore.m
Last active Dec 13, 2016
关系型数据库排序字段
View ItemStore.m
/*模型实现*/
double order;
if ([self.allItems count]==0) {
order = 1.0;
} else {
order = [[self.privateItems lastObject] orderingValue]+1.0;
}
NSLog(@"Adding after %d items, order=%.2f",[self.privateItems count], order);
/*模型实现*/
View AssetTypeViewController.m
-(instancetype)init {
return [super initWithStyle:UITableViewStylePlain];
}
-(instancetype)initWithStyle:(UITableViewStyle)style {
return [self init];
}
-(void)viewDidLoad {
[super viewDidLoad];
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"UITableViewCell"];
}
View num.playground
class NumbersParser: NumberParser {
static let sharedInstance = NumbersParser()
func numberToChinese(number: Int) -> String {
let numbers = String(number).characters
var finalString = ""
for singleNumber in numbers {
let string = singleNumberToChinese(number: singleNumber)
finalString = "\(finalString)\(string)"
}
return finalString
View num.playground
enum China: Int {
case Guangzhou = 0
case Beijing
var description: String {
switch self {
case .Guangzhou:
return "广州"
case .Beijing:
return "北京"
View ViewController.swift
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// 在这里销毁所有可以被重建的资源
}
View Swifter.playground
func addTo(_ adder: Int) -> (Int) -> Int {
return {
num in
return num + adder
}
}
let addTwo = addTo(2) //addTwo:Int -> Int
let result = addTwo(6) //result = 8
View selector.m
-(void) callMe {
//...
}
-(void) callMeWithParam:(id)obj {
//...
}
SEL someMethod = @selector(callMe);
SEL anotherMethod = @selector(callMeWithParam:);
View guard.swift
func objectAtIndexPath(indexPath: NSIndexPath) -> Object {
guard let result = fetchedResultsController.objectAtIndexPath(indexPath)
as? Object else
{
fatalError("Unexpected object at \(indexPath)")
}
return result
}
View optional.swift
let nickName: String? = nil
let fullName: String = "John Appleseed"
let informalGreeting = "Hi \(nickName ?? fullName)"
@josephchang10
josephchang10 / coredata.swift
Created Dec 21, 2016
Core Data ManagedObjectContextSettable 协议
View coredata.swift
protocol ManagedObjectContextSettable: class {
var managedObjectContext: NSManagedObjectContext! { get set }
}
You can’t perform that action at this time.