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 swapTwoInts(_ a: inout Int, _ b: inout Int) { | |
let temporaryA = a | |
a = b | |
b = temporaryA | |
} | |
var someInt = 3 | |
var anotherInt = 107 | |
swapTwoInts(&someInt, &anotherInt) | |
print("someInt 现在是 \(someInt),anotherInt 现在是 \(anotherInt)") |
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 swapTwoValues<Joseph>(_ a: inout Joseph, _ b: inout Joseph) { | |
let temporaryA = a | |
a = b | |
b = temporaryA | |
} | |
var someInt = 3 | |
var anotherInt = 107 | |
swapTwoValues(&someInt, &anotherInt) | |
print("someInt 现在是\(someInt),anotherInt 现在是 \(anotherInt)") |
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 fontSize: CGFloat = 22.0 | |
func sizeHeightWithText(labelText: NSString, | |
fontSize: CGFloat, | |
textAttributes: [String : Any]) -> CGRect { | |
return labelText.boundingRect( | |
with: CGSize(width:fontSize, height:480), | |
options: NSStringDrawingOptions.usesLineFragmentOrigin, | |
attributes: textAttributes, context: nil) |
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
import UIKit | |
func sizeHeightWithText(labelText: String, | |
fontSize: CGFloat, | |
textAttributes: [String : AnyObject]) -> CGRect { | |
return labelText.boundingRect( | |
with: CGSize(width:fontSize, height:480), | |
options: NSStringDrawingOptions.usesLineFragmentOrigin, | |
attributes: textAttributes, context: nil) |
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)initSearchBar | |
{ | |
searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 44)]; | |
[searchBar sizeToFit]; | |
searchBar.placeholder = [IFI18nUtils getLocalizedString:@"SEARCH"]; | |
searchBar.delegate = self; | |
searchBar.backgroundColor = [UIColor clearColor]; | |
[self.collectionView setContentInset:UIEdgeInsetsMake(-44, 0, 0, 0)]; | |
} |
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)initSearchBar | |
{ | |
searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 44)]; | |
[searchBar sizeToFit]; | |
searchBar.placeholder = [IFI18nUtils getLocalizedString:@"SEARCH"]; | |
searchBar.delegate = self; | |
searchBar.backgroundColor = [UIColor clearColor]; | |
[self.collectionView setContentInset:UIEdgeInsetsMake(-44, 0, 0, 0)]; | |
} |
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
NSSortDescriptor * descriptor = [[NSSortDescriptor alloc] initWithKey:@"interest" ascending:YES]; | |
stories = [stories sortedArrayUsingDescriptors:@[descriptor]]; | |
recent = [stories copy]; |
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
DispatchQueue.main.async { | |
self.imageView.image = image | |
} |
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 var prefersStatusBarHidden: Bool { | |
return true | |
} | |
override var supportedInterfaceOrientations: UIInterfaceOrientationMask { | |
return [UIInterfaceOrientationMask.portrait, UIInterfaceOrientationMask.portraitUpsideDown] | |
} |
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
/* myArray is a NSMutableArray with some objects */ | |
NSUInteger count = [myArray count]; | |
for (NSUInteger i = 0; i < count; ++i) { | |
int nElements = count - i; | |
int n = (arc4random() % nElements) + i; | |
[myArray exchangeObjectAtIndex:i withObjectAtIndex:n]; | |
} |