This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*模型实现*/ | |
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); | |
/*模型实现*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(instancetype)init { | |
return [super initWithStyle:UITableViewStylePlain]; | |
} | |
-(instancetype)initWithStyle:(UITableViewStyle)style { | |
return [self init]; | |
} | |
-(void)viewDidLoad { | |
[super viewDidLoad]; | |
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"UITableViewCell"]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum China: Int { | |
case Guangzhou = 0 | |
case Beijing | |
var description: String { | |
switch self { | |
case .Guangzhou: | |
return "广州" | |
case .Beijing: | |
return "北京" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override func didReceiveMemoryWarning() { | |
super.didReceiveMemoryWarning() | |
// 在这里销毁所有可以被重建的资源 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(void) callMe { | |
//... | |
} | |
-(void) callMeWithParam:(id)obj { | |
//... | |
} | |
SEL someMethod = @selector(callMe); | |
SEL anotherMethod = @selector(callMeWithParam:); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func objectAtIndexPath(indexPath: NSIndexPath) -> Object { | |
guard let result = fetchedResultsController.objectAtIndexPath(indexPath) | |
as? Object else | |
{ | |
fatalError("Unexpected object at \(indexPath)") | |
} | |
return result | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let nickName: String? = nil | |
let fullName: String = "John Appleseed" | |
let informalGreeting = "Hi \(nickName ?? fullName)" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol ManagedObjectContextSettable: class { | |
var managedObjectContext: NSManagedObjectContext! { get set } | |
} |
OlderNewer