//
// main.m
// cmdTry
//
// Created by Calos Chen on 2017/8/21.
// Copyright © 2017年 Calos Chen. All rights reserved.
// #import <Foundation/Foundation.h>
#import "class4.m"
#import "NSObject_class5.h" @class Fraction;
@interface Fraction : NSObject
{
int numberator;
int denominator;
NSString* name;
@public
double price;
Fraction *myf; }
@property double price;
-(void) print;
-(void) setNumberator: (int)n;
-(void) setName: (NSString*)na;
-(void) setInfo: (int) id name:(NSString*)name; @end @implementation Fraction @synthesize price; -(void) print
{
name= [name getBy:23 andName:@"Ok"];//
NSLog(@"%i it is %@",numberator,name);
}
-(void) setNumberator:(int)n
{
price=5;
numberator=n;
}
-(void)setName:(NSString *)na{
name=na;
} -(void) setInfo:(int)id name:(NSString *)na{
id=id;
name=na;
} @end //---- program section ---- int main(int argc, const char * argv[]) {
@autoreleasepool {
// insert code here...
NSLog(@"Hello, World!");
NSLog(@"who are you!");
}
NSNumber *xdd;
xdd=[NSNumber numberWithInt:45]; NSLog(@"why is it");
Fraction *myf= [[Fraction alloc] init];
[myf setName:@"calos"];
[myf print];
double price=myf->price; int a1=5;
float a2=3.23;
double a3=3.44;
char a4='c';
int a5=(int)a2;
for (int b=1; b<10;b++ ) {
a5+=b;
}
myf.price=88;
double b1=myf.price;
BOOL isPrime=NO;
NSLog(@"%i %f %e %c %i %c %g %e",a1,a2,a3,a4,a5,isPrime,b1,price);
NSLog(@"end........"); //file write
NSFileManager* fm=[NSFileManager defaultManager];
NSString* fname=@"a.txt";
NSFileHandle* fh=[NSFileHandle new];
NSData* data=nil;
NSCoder* coder=[NSCoder new];
[fm createFileAtPath:fname contents:nil attributes:nil];
if([fm isReadableFileAtPath:fname]){
[fh writeData:data];
}
else{
[[fh initWithCoder:coder] writeData:data];
} // 初始化管理类
NSFileManager * manager = [NSFileManager
defaultManager]; // 路径
NSString * DirectoryPath = [NSHomeDirectory()
stringByAppendingPathComponent:@"/desktop/我的文件夹1/我的文件夹2"]; NSError * error =
nil;
if ([manager
createDirectoryAtPath:DirectoryPath
withIntermediateDirectories:NO
attributes:nil
error:&error] !=
YES) {
// NSString * str = [error localizedDescription];
NSLog(@"创建失败");
}else {
// NSString * str = [error localizedDescription];
NSLog(@"创建成功");
} //file handle NSFileHandle *inFile, *outFile;
NSData *buffer;
NSData* d1=[@"sss" dataUsingEncoding:NSUTF8StringEncoding];
[[NSFileManager defaultManager] createFileAtPath:@"test.txt" contents:d1 attributes:nil]; //打开testfile.txt文件用于读取操作
inFile = [NSFileHandle fileHandleForReadingAtPath:@"testfile.txt"]; if(inFile == nil)
{
NSLog(@"Open of testfile.txt for reading failed!");
return 1;
} //创建一个文件用于写数据(第一次是必要的)
[[NSFileManager defaultManager] createFileAtPath:@"testout.txt" contents:nil attributes:nil] ; //打开testout.txt文件用于写入操作
outFile = [NSFileHandle fileHandleForWritingAtPath:@"testout.txt"]; if(outFile == nil)
{
NSLog(@"Open of testout.txt for writing failed!");
return 2;
} //
[outFile truncateFileAtOffset:0]; //从inFile中读取数据,并将其写入到outFile中
buffer = [inFile readDataToEndOfFile]; [outFile writeData:buffer]; //关闭两个文件
[inFile closeFile];
[outFile closeFile]; return 0;
} //for today: 2017-08-21, I have read and practiced the first 153 pages of the object-c 2.0, now, I have known object-c classes and data types, and how to announce and implement the classes and class members, as well as functions in the class implementation. also property synthesize methods. loops.
//homework: implement a new class, and new interface and fill the class with members and all tangible members, then use all of them. @class declaration. So, write a console program with object-c.
目前可以使用 Object-c 的 file 处理, 可以操作目录,并读写文件, 控制台程序生成了正常的文件,感觉比较欣慰,文件处理也算蛮大的一步了,知道了一些 oc 常用的库处理,在渐渐地变熟练
[object-c 2.0 程序设计]object-c file handle (二)的更多相关文章
-
document.forms[0].submit object is not a function
今天在做项目的时候发现了一个问题:document.forms[0].submit object is not a function. 这个问题是在用JavaScript 代码来提交一个表单时发生的. ...
-
Terminating app due to uncaught exception &#39;NSInvalidArgumentException&#39;, reason: &#39;*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0]&#39;
报错: Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlace ...
-
* -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0]’
错误描述: * -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object fr ...
-
原型相关的方法isPrototypeOf、Object.getPrototypeOf、hasOwnProperty、Object.getOwnPropertyName、Object.keys
在看<高程3>第六章的<面向对象的程序设计>的原型那一节时,有一下5个函数,功能较为接近,但是又都很基础,很重要 所以在此,加以说明,以便日后复习 function Perso ...
-
Android学习笔记_46_Android的intent之间Object、List、List<;Object>;和全局变量数据的传递(Parcelable Serializable)
转http://blog.csdn.net/pku_android/article/details/7456305 一.传递List<String>和List<Integer> ...
-
List<;List<;Object>;>; list = new ArrayList<;List<;Object>;>;(); 求回答补充问题 list.get(position).add(Object);为什么会报错啊我想在对应的list里面添加对象
public static void main(String[] args){ List<List<Object>> list = new ArrayList<List& ...
-
PHP json_decode object时报错Cannot use object of type stdClass as array
PHP json_decode object时报错Cannot use object of type stdClass as array php再调用json_decode从字符串对象生成json对象 ...
-
自己写的demo。List<;HashMap<;String,Object>;>;=new ArrayList<;HashMap<;String,Object>;>;
package com.pb.collection; import java.util.ArrayList; import java.util.HashMap; import java.util.It ...
-
关于 warning CS0659:“***”重写Object.Equals(object o)但不重写Object.GetHashCode()
对象相等性和同一性 System.Object 类型提供了以下方法, namespace System { // // 摘要: // 支持 .NET Framework 类层次结构中的所有类,并为派生 ...
随机推荐
-
【iCore3 双核心板】例程二十二:LAN_UDP实验——以太网数据传输
实验指导书及代码包下载: http://pan.baidu.com/s/1kTPlJMJ iCore3 购买链接: https://item.taobao.com/item.htm?id=524229 ...
-
Context启动startActivity注意
intent.setFlags()方法中参数的用例: 很多人使用startActivity时候,会碰到如下的异常:Caused by: android.util.AndroidRuntimeExcep ...
-
C++ (P103—P154)
1 任一指针变量本身的数据值得类型都是unsigned long int 2 指针值为0的叫做空指针,为了安全起见,声明指针时最好初始化,哪怕是初始化为空指针 3 一般不能使用不同类型变量的地址来给指 ...
-
[Swust OJ 217]--Factor(数论,类素数表)
题目链接:http://acm.swust.edu.cn/problem/0217/ Time limit(ms): 2000 Memory limit(kb): 65535 Descripti ...
-
201521123108 《Java程序设计》第7周学习总结
1. 本周学习总结 2. 书面作业 Q1.ArrayList代码分析 Q1.1 解释ArrayList的contains源代码 答:源代码如下: public boolean contains(Obj ...
-
移动端1px边框实现
问题描述:移动端iPhone上的1px边框看起来像2px那么粗.问题分析:不同的手机有不同的像素密度,在window对象中有一个devicePixelRatio属性,它可以反应设备的像素与css中的像 ...
-
团体程序设计天梯赛(CCCC) L3014 周游世界 BFS证明
团体程序设计天梯赛代码.体现代码技巧,比赛技巧. https://github.com/congmingyige/cccc_code
-
python 字符串编码解码和格式化问题
转自:https://www.liaoxuefeng.com/wiki/001374738125095c955c1e6d8bb493182103fac9270762a000/0013868191962 ...
-
iOS保存gif动态图
- (void)saveImageToPhotos:(NSData*)gifData { /***注意先倒入库 #import <AssetsLibrary/AssetsLibrary.h> ...
-
sha256sum和 md5sum 命令之间的区别
Short answer: For verifying ISOs, there is no practical difference, use whichever you want, as long ...