This file contains hidden or 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
//: Playground - noun: a place where people can play | |
import Foundation | |
var str = "Hello" | |
let data1 = str.data(using: String.Encoding.utf8)! | |
data1.withUnsafeBytes { (bytes: UnsafePointer<CChar>) -> Void in | |
print(bytes.pointee) | |
let arr = UnsafeBufferPointer(start: bytes, count: 5) |
This file contains hidden or 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
int main(int argc, const char * argv[]) { | |
/* 指针、引用和取值 | |
int *ptr; // 声明一个 int 指针 | |
int val = 1; // 声明一个 int 值 | |
ptr = &val; // 为指针分配一个 int 值的引用 | |
int deref = *ptr; // 对指针进行取值 | |
int nullVal; // 默认值是 0 | |
int *nullPtr = &nullVal; | |
printf("Hello, World!\n%p=%d\n%p=%d\n", ptr, deref, nullPtr, nullVal); |
This file contains hidden or 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
# default.custom.yaml | |
# save it to: | |
# ~/.config/ibus/rime (linux) | |
# ~/Library/Rime (macos) | |
# %APPDATA%\Rime (windows) | |
patch: | |
schema_list: | |
- schema: luna_pinyin # 朙月拼音 | |
- schema: luna_pinyin_simp # 朙月拼音 简化字模式 |
This file contains hidden or 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
#pragma mark - | |
- (void)drawTestLine | |
{ | |
// test code : draw line between Beijing and Hangzhou | |
CLLocation *location0 = [[CLLocation alloc] initWithLatitude:39.954245 longitude:116.312455]; | |
CLLocation *location1 = [[CLLocation alloc] initWithLatitude:30.247871 longitude:120.127683]; | |
NSArray *array = [NSArray arrayWithObjects:location0, location1, nil]; | |
[self drawLineWithLocationArray:array]; | |
} |
This file contains hidden or 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
// 添加通知 | |
[[UIDevice currentDevice] setProximityMonitoringEnabled:YES]; | |
if ([UIDevice currentDevice].proximityMonitoringEnabled == YES) | |
[[NSNotificationCenter defaultCenter] addObserver:self | |
selector:@selector(proximitySensorChange:) | |
name:UIDeviceProximityStateDidChangeNotification | |
object:nil]; | |
// 移除通知 | |
if ([UIDevice currentDevice].proximityMonitoringEnabled == YES) |
This file contains hidden or 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
#pragma mark - CLLocationManagerDelegate | |
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error { | |
switch (error.code) { | |
case kCLErrorLocationUnknown: | |
NSLog(@"The location manager was unable to obtain a location value right now."); | |
break; | |
case kCLErrorDenied: | |
NSLog(@"Access to the location service was denied by the user."); | |
break; | |
case kCLErrorNetwork: |
This file contains hidden or 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
- (IBAction)openGPS:(id)sender { | |
if (locationManager == nil) { | |
locationManager = [[CLLocationManager alloc] init]; | |
locationManager.delegate = self; | |
locationManager.desiredAccuracy = kCLLocationAccuracyBest; // 越精确,越耗电! | |
} | |
[locationManager startUpdatingLocation]; // 开始定位 | |
} |
This file contains hidden or 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
CLLocationManager *manager = [[CLLocationManager alloc] init]; | |
if (manager.locationServicesEnabled == NO) { | |
UIAlertView *servicesDisabledAlert = [[UIAlertView alloc] initWithTitle:@"Location Services Disabled" message:@"You currently have all location services for this device disabled. If you proceed, you will be asked to confirm whether location services should be reenabled." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; | |
[servicesDisabledAlert show]; | |
[servicesDisabledAlert release]; | |
} |
This file contains hidden or 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
// declare | |
@property (retain) NSTimer *unregisteredTimer; | |
// implements | |
- (IBAction)createUnregisteredTimer:sender { | |
NSMethodSignature *methodSignature = [self methodSignatureForSelector:@selector(invocationMethod:)]; |
This file contains hidden or 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
// declcare | |
@property (assign) NSTimer *repeatingTimer; | |
// implements | |
- (IBAction)startRepeatingTimer:sender { | |
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:0.5 |