nil: A null pointer to an Objective-C object.
( #define nil ((id)0) )
Nil: A null pointer to an Objective-C class.
NULL: A null pointer to anything else, is for C-style memory pointers.
( #define NULL ((void *)0) )
NSNull: A class defines a singleton object used to represent null values in collection objects (which don't allow nil values).
[NSNull null]: The singleton instance of NSNull.
Technically they're all the same,,, but in practice they give someone reading your code some hints about what's going on; just like naming classes with a capital letter and instances with lowercase is recommended, but not required.
If someone sees you passing NULL, they know the receiver expects a C pointer. If they see nil, they know the receiver is expecting an object. If they see Nil, they know the receiver is expecting a class. Readability.
if obj is nil , [obj message] will return NO, without NSException
if obj is NSNull , [obj message will throw a NSException
[NSApp beginSheet:sheet modalForWindow:mainWindow modalDelegate:nil //pointing to an object didEndSelector:NULL //pointing to a non object/class contextInfo:NULL]; //pointing to a non object/class
NSObject *obj1; if (obj1 != nil) { NSLog(@"object is not nil"); }else { NSLog(@"object is nil"); } testClass *c1; if (c1 != Nil) { NSLog(@"class is not Nil"); }else { NSLog(@"class is Nil"); } int *money; if (money != NULL) { NSLog(@"money is not NULL"); }else { NSLog(@"money is NULL"); }
NSObject *obj1 = [[NSObject alloc] init]; NSObject *obj2 = [NSNull null]; NSObject *obj3 = [NSObject new]; NSObject *obj4; NSArray *arr1 = [NSArray arrayWithObjects:obj1, obj2, obj3, obj4, nil]; NSLog(@"arr1 count: %ld", [arr1 count]); //arr1 count: 3 NSObject *obj1; NSObject *obj2 = [[NSObject alloc] init]; NSObject *obj3 = [NSNull null]; NSObject *obj4 = [NSObject new]; NSArray *arr2 = [NSArray arrayWithObjects:obj1, obj2, obj3, obj4, nil]; NSLog(@"arr2 count: %ld", [arr2 count]); //arr2 count: 0
//有异常! NSObject *obj1 = [NSNull null]; NSArray *arr1 = [NSArray arrayWithObjects:@"One", @"TWO", obj1, @"three" ,nil]; for (NSString *str in arr1) { NSLog(@"array object: %@", [str lowercaseString]); } //修改 NSObject *obj1 = [NSNull null]; NSArray *arr1 = [NSArray arrayWithObjects:@"One", @"TWO", obj1, @"three" ,nil]; for (NSString *str in arr1) { if (![str isEqual:[NSNull null]]){ NSLog(@"array object: %@", [str lowercaseString]); } }
获取本机IP、MAC,判断网络是否可用,获取wifi状态 public class NetworkUtil { /** * 获取本机IP * * @return */ public static String getIpAddress() { try { Enumeration<NetworkInterface> enumeration = NetworkInterface .getNetworkInterfaces(); while (enumeration.hasMoreElements()) { NetworkInterface nextElement = enumeration.nextElement(); Enumeration<InetAddress> enIp = nextElement.getInetAddresses(); while (enIp.hasMoreElements()) { InetAddress ipaddress = enIp.nextElement(); if (!ipaddress.isLoopbackAddress()) { return ipaddress.getHostAddress().toString(); } } } } catch (SocketException e) { e.printStackTrace(); } return null; } /** * 判断网络是否可用 * * @param context * @return */ public static boolean isConnect(Context context) { // 获取手机所有连接管理对象(包括对wi-fi,net等连接的管理) try { ConnectivityManager connectivity = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); if (connectivity != null) { // 获取网络连接管理的对象 NetworkInfo info = connectivity.getActiveNetworkInfo(); if (info != null && info.isConnected()) { // 判断当前网络是否已经连接 if (info.getState() == NetworkInfo.State.CONNECTED) { return true; } } } } catch (Exception e) { Log.v("====", e.toString()); } return false; } /** * 获取本机MAC地址 * * @param ctx * @return */ public static String getMacAddress(Context ctx) { WifiManager wfMgr = (WifiManager) ctx .getSystemService(Context.WIFI_SERVICE); WifiInfo info = wfMgr.getConnectionInfo(); return info.getMacAddress(); } /** * 获取wifi状态 * * @param ctx * @return */ public static String getNetWorkStatus(Context ctx) { WifiManager wfMgr = (WifiManager) ctx .getSystemService(Context.WIFI_SERVICE); int state = wfMgr.getWifiState(); String status = null; switch (state) { case WifiManager.WIFI_STATE_DISABLED: status = "使用不可(DISABLED)"; break; case WifiManager.WIFI_STATE_DISABLING: status = "停止中(DISABLING)"; break; case WifiManager.WIFI_STATE_ENABLED: status = "使用可(ENABLED)"; break; case WifiManager.WIFI_STATE_ENABLING: status = "起動中(ENABLING)"; break; case WifiManager.WIFI_STATE_UNKNOWN: status = "未知(UNKNOWN)"; break; } WifiInfo info = wfMgr.getConnectionInfo(); status += " AP MAC(" + info.getBSSID() + ") DBM値(" + info.getRssi() + ")"; return status; } }
git的check in过程分两步:
1.添加跟踪或者更新已经被git跟踪的文件.
命令:git add filename。如果文件是第一次add,则称为添加跟踪(add to index)。如果文件已经添加过跟踪,有所改动后调用该命令则称为更新。
2.提交
命令:git commit
实例2:删除文件,删除文件跟踪
接着上面的状态,此时我们想从工程中删除file1,以后git再也不用管理该文件:
方法1:
git rm file1 //删除文件跟踪并且删除文件系统中的文件file1
git commit //提交刚才的删除动作,之后git不再管理该文件。
方法2:
git rm --cached file1 //删除文件跟踪但不删除文件系统中的文件file1
git commit //提交刚才的删除动作,之后git不再管理该文件。但是文件系统中还是有file1。