当前位置:  编程技术>移动开发
本页文章导读:
    ▪Objective-c 中 nil, Nil, NULL跟NSNull的区别        Objective-c 中 nil, Nil, NULL和NSNull的区别 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 .........
    ▪ 手机网络环境有关的代码        手机网络环境相关的代码 获取本机IP、MAC,判断网络是否可用,获取wifi状态 public class NetworkUtil { /** * 获取本机IP * * @return */ public static String getIpAddress() { try { Enumeration<NetworkI.........
    ▪ git 平添删除       git 添加删除 git的check in过程分两步: 1.添加跟踪或者更新已经被git跟踪的文件.    命令:git add filename。如果文件是第一次add,则称为添加跟踪(add to index)。如果文件已经添加过跟踪,有所改.........

[1]Objective-c 中 nil, Nil, NULL跟NSNull的区别
    来源: 互联网  发布时间: 2014-02-18
Objective-c 中 nil, Nil, NULL和NSNull的区别

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]);
            }
        } 

 


    
[2] 手机网络环境有关的代码
    来源: 互联网  发布时间: 2014-02-18
手机网络环境相关的代码
获取本机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;
	}

}

 


    
[3] git 平添删除
    来源: 互联网  发布时间: 2014-02-18
git 添加删除

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。


    
最新技术文章:
▪Android开发之登录验证实例教程
▪Android开发之注册登录方法示例
▪Android获取手机SIM卡运营商信息的方法
▪Android实现将已发送的短信写入短信数据库的...
▪Android发送短信功能代码
▪Android根据电话号码获得联系人头像实例代码
▪Android中GPS定位的用法实例
▪Android实现退出时关闭所有Activity的方法
▪Android实现文件的分割和组装
▪Android录音应用实例教程
▪Android双击返回键退出程序的实现方法
▪Android实现侦听电池状态显示、电量及充电动...
▪Android获取当前已连接的wifi信号强度的方法
▪Android实现动态显示或隐藏密码输入框的内容
▪根据USER-AGENT判断手机类型并跳转到相应的app...
▪Android Touch事件分发过程详解
▪Android中实现为TextView添加多个可点击的文本
▪Android程序设计之AIDL实例详解
▪Android显式启动与隐式启动Activity的区别介绍
▪Android按钮单击事件的四种常用写法总结
▪Android消息处理机制Looper和Handler详解
▪Android实现Back功能代码片段总结
▪Android实用的代码片段 常用代码总结
▪Android实现弹出键盘的方法
▪Android中通过view方式获取当前Activity的屏幕截...
▪Android提高之自定义Menu(TabMenu)实现方法
▪Android提高之多方向抽屉实现方法
▪Android提高之MediaPlayer播放网络音频的实现方法...
▪Android提高之MediaPlayer播放网络视频的实现方法...
▪Android提高之手游转电视游戏的模拟操控
 


站内导航:


特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

©2012-2021,,E-mail:www_#163.com(请将#改为@)

浙ICP备11055608号-3