- Jan 25 Sun 2015 02:08
很適合當律師的.......逆子
- Jan 23 Fri 2015 12:57
Objective-C與C++不同的地方
來源:http://blog.diveinedu.net/objective-c不和c那样有函数重载/
今天有学员问在看Programming iOS 6的书上看到OC里不能像C++那样形式做函数重载的问题.
No Overloading
The data type returned by a method, together with the data types of each of its param‐ eters in order, constitute that method’s signature. It is illegal for two methods of the same type (class method or instance method) to exist in the same class with the same name but different signatures.
So, for example, you could not have two MyClass instance methods called myMethod, one of which returns void and one of which returns an NSString. Similarly, you could not have two MyClass instance methods called myMethod:, both returning void, one taking a CGFloat parameter and one taking an NSString parameter. An attempt to vi‐ olate this rule will be stopped dead in its tracks by the compiler, which will announce a “duplicate declaration” error. The reason for this rule is that if two such conflicting methods were allowed to exist, there would be no way to determine from a method call to one of them which method was being called.
You might think that the issue could be decided by looking at the types involved in the call. If one myMethod: takes a CGFloat parameter and the other myMethod: takes an NSString parameter, you might think that when myMethod: is called, Objective-C could look at the actual argument and realize that the former method is meant if the argument is a CGFloat and the latter if the argument is an NSString. But Objective-C doesn’t work that way. There are languages that permit this feature, called overloading, but Objective- C is not one of them.
我在这阐述一下这2个OO语言之间的一些异同:
1, 两者最大的相同便是: 都是从 C 演化而来的面向对象语言, 两者都兼容标准 C 语言.
2, 两者最大的不同便是: Objective C 是完全动态(运行时绑定)的,而 C++是部分动态的(编译时绑定和运行时绑定)。
Objective C 支持在运行时动态类型决议(dynamic typing),动态绑定(dynamic binding)以及动态装载(dynamic loading);
- Jan 23 Fri 2015 12:53
iOS程式object-c與javasript互相呼叫
來源:http://nscoder.me
还记得以前在网页上用 iframe
指定一个 URL 并通过 native 的 - webView:shouldStartLoadWithRequest:navigationType:
回调方法拦截请求,再蛋疼的各种截取和判断字符串,结合 json 结构的字符串来获取 web 端发来的数据。
通过 - stringByEvaluatingJavaScriptFromString:
来拼接老长的字符串来传递数据给 web 端吗。。。
现在我们可以对这种方式说 「爱过~」 了。
先看一下 Objective-C 与 JavaScript 之间类型的对应关系
Objective-C type | JavaScript type |
---|---|
nil | undefined |
NSNull | null |
NSString | string |
NSNumber | number, boolean |
NSDictionary | Object object |
NSArray | Array object |
NSDate | Date object |
NSBlock | Function object |
id | Wrapper object |
Class | Constructor object |
返回的 JSValue 转换为 Objective-C 类型的方法
我们主要使用的是 JSContext
这个类,下面通过几个简单的例子来演示。
首先需要加入 JavaScriptCore.framework 并引入。
Objective-C 调用纯 JavaScript
例如有一段计算阶乘的脚本
- Jan 23 Fri 2015 12:51
IOS8獲取當前經緯度、地理位置
IOS8获取当前经纬度、地理位置
/*集成说明:
1、在plist添加
NSLocationAlwaysUsageDescription = YES
NSLocationWhenInUseUsageDescription = YES
2、导入CCLocationManager.h头文件
3、通过block回调获取经纬度、地理位置等
*/
程式碼載點http://code.cocoachina.com/detail/280904
- Jan 23 Fri 2015 08:52
[iOS]推播錯誤
- Jan 23 Fri 2015 08:52
台灣風車~後龍風力發電(2014/12/28 )