按月查看: 三月 2013

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. [......]

Read more

文章分类 iPhone应用开发

wordpress时间函数the_time用法详解

这两天一直在用WordPress打造企业展示站点,里面用到了一些WP的标签,其中时间标签用得挺多的,稍微多了解了一下。

代码如下:

<?php the_time(‘Y-m-d’); ?>

显示的是 2011-10-1 这样的,修改()中内容用以下字符替换可以达到相应效果。

代[......]

Read more

标签: , ,
文章分类 Linux服务器开发

good

文章分类 未分类