Objective C 基础

 

1、字符串加@:

不加@的是C语言字符串。

加@的代表的是OC的NSString 

http://www.jikexueyuan.com/course/71_2.html

 

2、setValuesForKeysWithDictionary

http://www.cnblogs.com/YouXianMing/p/3641304.html

 

3、instancetype只能作为返回值,不能像id那样作为参数。

 

4、UIActionSheet

- (IBAction)showSheet:(id)sender {
UIActionSheet *actionSheet = [[UIActionSheet alloc]
initWithTitle:@"title,nil时不显示"
delegate:self
cancelButtonTitle:@"取消"
destructiveButtonTitle:@"确定"
otherButtonTitles:@"第一项", @"第二项",nil];
actionSheet.actionSheetStyle = UIActionSheetStyleBlackOpaque;
[actionSheet showInView:self.view];

转成Swift 

直接调用ActionSheet的 init(title: String?, delegate: UIActionSheetDelegate?, cancelButtonTitle: String?, destructiveButtonTitle: String?)

方法不行。必须 分开写才行。

actionSheet = UIActionSheet()

            actionSheet.title =   Str_label_goods_category

            actionSheet.delegate = self

            for (var k = 0 ;k < str.count ; k++ )

            {

            actionSheet.addButtonWithTitle(str[k])

            }

            actionSheet.actionSheetStyle  =  UIActionSheetStyle.BlackOpaque

            actionSheet.showInView(self)

 

 

 

5、oc 的文件导入swift项目中

如果OC的代码非arc的,需要在compile source  里面给该文件更改Compiler Flags为-fno-objc-arc 

arc的不需要。

 

UIView

6、frame,bounds,center

bounds 只有宽和高是有效的。

7、常用函数

-(void)removeFromSuperview;

-(void)insertSubview:(UIView *)view atIndex:(NSInteger)index;

-(void)exchangeSubviewAtIndex:(NSInteger)index1 withSubviewAtIndex:(NSInteger)index2;

-(void)addSubview:(UIView*)view;

-(UIView*)viewWithTag:(NSInteger)tag;

8、粗体

label.font = UIFont(name: "Helvetica-Bold", size: 32/2)

9、pageControl 小圆点的颜色

        pageControl.pageIndicatorTintColor = UIColor.grayColor()

        pageControl.currentPageIndicatorTintColor =  UIColor(white: 0.7, alpha: 0.5) 

10、将程序发布到Appstore : Product——>Archive ——>Distribute——>Submit to the appstore ——>next 

11、swift 类的功能扩展:

extension className{

func  funName()

{}

则className和它的子类都拥有新的func。

命名空间

class com{

class study{

}

}

extension com.study{

class Hello{

func sayHello(){....}

}

}

extension com.study{

class Hi{

func sayHi(){....}
}

}

12、view1切换到view2

 UIView.transitionFromView(view1, toView:view2, duration:0.3, options:UIViewAnimationOptions.TransitionFlipFromTop,nil)

13、

深拷贝和浅拷贝(mutableCopy和Copy)详解

http://www.cnblogs.com/foxmin/archive/2012/07/05/2577154.html 

 

然后在supporting Files里面的jj-Bridging-Header.h里面加入#import<*****.h> (#include"***.h"也行)

 

14、oc项目调用swift

oc头部引用#import"项目名-swift.h"

 

posted @   尘恍若梦  阅读(144)  评论(0编辑  收藏  举报
编辑推荐:
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
点击右上角即可分享
微信分享提示