小编Joe*_*Joe的帖子

如何在应用程序中在运行时获取控制台读数?

出于调试目的,我想在运行时以类似于App Store上的Console app(可在此处找到)的方式访问控制台打印输出.

我做了一些搜索文档,我找不到Apple提供的任何东西,但我觉得我错过了一些重要的东西.任何见解?

谢谢.

console objective-c ios

12
推荐指数
1
解决办法
9256
查看次数

方法[[UIDevice currentDevice] uniqueIdentifier]不再允许,我需要一个替代方案

我正在使用我的[[UIDevice currentDevice] uniqueIdentifier]所有应用程序,Apple不再允许使用它uniqueIdentifier.我需要一些东西来代替uniqueIdentifier我用来识别用户的东西,即使用户删除了应用程序并再次安装它,(并且还得到苹果批准我的应用程序).

谢谢

xcode objective-c ios

8
推荐指数
1
解决办法
7028
查看次数

"pod install"命令在Mac OS X上有什么作用?

我正在观看有关使用XCode和Heroku创建iOS应用的视频.在zsh中键入以下命令:

pod install
Run Code Online (Sandbox Code Playgroud)

我想知道是否有人可以解释这是什么以及它用于什么?简单的概述就足够了.

macos xcode zsh heroku ios

8
推荐指数
1
解决办法
5446
查看次数

使用@autoreleasepool减少峰值内存使用量

我在一个iPad应用程序上工作,该应用程序具有一个紧密循环使用Web服务和Core Data的同步过程.为了根据Apple的Recomendation减少内存占用,我会NSAutoreleasePool定期分配和排空.这当前效果很好,当前应用程序没有内存问题.但是,我打算转移到NSAutoreleasePool不再有效的ARC,并希望保持同样的性能.我创建了一些示例并计算了它们,我想知道使用ARC的最佳方法是什么,以实现相同的性能并保持代码可读性.

出于测试目的,我想出了3个场景,每个场景使用1到10,000,000之间的数字创建一个字符串.我运行了每个例子3次,以确定他们使用带有Apple LLVM 3.0编译器(w/o gdb -O0)和XCode 4.2的Mac 64位应用程序花了多长时间.我还通过仪器运行每个示例,以大致了解内存峰值.

以下每个示例都包含在以下代码块中:

int main (int argc, const char * argv[])
{
    @autoreleasepool {
        NSDate *now = [NSDate date];

        //Code Example ...

        NSTimeInterval interval = [now timeIntervalSinceNow];
        printf("Duration: %f\n", interval);
    }
}
Run Code Online (Sandbox Code Playgroud)

NSAutoreleasePool批次[原始预ARC](峰值内存:~116 KB)

    static const NSUInteger BATCH_SIZE = 1500;
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    for(uint32_t count = 0; count < MAX_ALLOCATIONS; count++)
    {
        NSString *text = [NSString stringWithFormat:@"%u", count + 1U];
        [text class]; …
Run Code Online (Sandbox Code Playgroud)

memory-management objective-c nsautoreleasepool ios automatic-ref-counting

7
推荐指数
1
解决办法
2581
查看次数

未知的类型名称'class'; 你的意思是'上课'吗?AurioTouch

我正在尝试将代码从AurioTouch项目移动到我的项目中.但我有很多错误:

Unknown type name 'class'; did you mean 'Class'?
Run Code Online (Sandbox Code Playgroud)

例如,在文件FFTBufferManager.h中:

#include <AudioToolbox/AudioToolbox.h>
#include <libkern/OSAtomic.h>

#include "SpectrumAnalysis.h"

class FFTBufferManager
{
public:
    FFTBufferManager(UInt32 inNumberFrames);
    ~FFTBufferManager();
Run Code Online (Sandbox Code Playgroud)

我试图将编译器更改为LLVM GCC 4.2,但它会产生很多其他错误:

Expected '=', ',', ';', 'asm' or '__attribute__' before 'FFTBufferManager'
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

c++ xcode objective-c objective-c++

6
推荐指数
1
解决办法
8991
查看次数

按字典键排序可变数组

我已经使用各种排序方法查看了几个答案NSMutableArray,但由于某种原因它们不适合我.

我只是试图通过Delay每个字典中的键对包含字典的可变数组进行排序.但是,"sorted"数组与原始数组完全相同.

顺便说一句,如果我创建一个虚拟可变数组并用包含数字的字典填充它,它可以正常工作,但由于某种原因它不会对我正在初始化的这个可变数组进行排序.

我究竟做错了什么?

这是我的代码:

playlistCalls = [[NSMutableArray alloc] initWithArray:[currentPlaylist objectForKey:@"Tunes"]];

NSLog(@"original %@", playlistCalls);

NSSortDescriptor *delay = [NSSortDescriptor sortDescriptorWithKey:@"Delay" ascending:YES];
[playlistCalls sortUsingDescriptors:[NSArray arrayWithObject:delay]];

NSLog(@"sorted %@", playlistCalls);
Run Code Online (Sandbox Code Playgroud)

这是包含字典的数组:

2012-06-04 15:48:09.129 MyApp[57043:f503] original (
        {
        Name = Test Tune;
        Delay = 120;
        Volume = 100;
    },
        {
        Name = Testes;
        Delay = 180;
        Volume = 100;
    },
        {
        Name = Testing;
        Delay = 60;
        Volume = 100;
    }
)

2012-06-04 15:48:09.129 MyApp[57043:f503] sorted (
        {
        Name = Test …
Run Code Online (Sandbox Code Playgroud)

sorting iphone objective-c nsmutablearray ios

6
推荐指数
1
解决办法
1100
查看次数

不确定NSProgressIndicator将不会动画

所以我有一个简单的用户界面,一个开始按钮,一些文本/标签和一个进度条.单击"开始"按钮时,NSProgressIndicator 设置动画.这是我的代码:

@synthesize progressBar = progressBar;
 /* Some code and setup stuffs... */
- (IBAction)startAction:(id)sender {
    NSLog(@"Button clicked.");
    NSLog(@"Beginning Socketry and socket creation...");
    [progressBar setUsesThreadedAnimation:YES];
    [progressBar setIndeterminate:YES];
    [progressBar startAnimation:progressBar];
}
Run Code Online (Sandbox Code Playgroud)

我检查了多个源(Apple Developer Portal等),但没有任何效果.我不必拥有NSPIndicator,但如果可以的话,它会非常好.另外,这是我的AppDelegate.h文件:

#import <Cocoa/Cocoa.h>

@interface AppDelegate : NSObject <NSApplicationDelegate>

@property (assign) IBOutlet NSWindow *window;

@property (readonly, strong, nonatomic) NSPersistentStoreCoordinator *persistentStoreCoordinator;
@property (readonly, strong, nonatomic) NSManagedObjectModel *managedObjectModel;
@property (readonly, strong, nonatomic) NSManagedObjectContext *managedObjectContext;
@property (weak) IBOutlet NSProgressIndicator *progressBar;
- (IBAction)saveAction:(id)sender;

- (IBAction)startAction:(id)sender;

- (IBAction)changeStatus:(id)sender;

- (IBAction)changeProgress:(id)sender;

@end
Run Code Online (Sandbox Code Playgroud)

animation objective-c nsprogressindicator ibaction

6
推荐指数
1
解决办法
8775
查看次数

如何在objective-c中取消计划NSTimer

我在应用程序中使用嵌套的NSTimer.我这里有两个问题.

  1. 如何在此功能中重新启动时间计数器 - (void)updateLeftTime:(NSTimer *)theTimer
  2. 如何杀死前一个计时器因为- (void)updateLevel:(NSTimer *)theTimer也是由计时器调用.

- (void)viewDidLoad {
    [super viewDidLoad];

    tmLevel=[NSTimer scheduledTimerWithTimeInterval:20.0f target:self selector:@selector(updateLevel:) userInfo:nil repeats:YES];

    tmLeftTime=[NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(updateLeftTime:) userInfo:nil repeats:YES];
}

- (void)updateLevel:(NSTimer *)theTimer {
    static int count = 1;
    count += 1;

    lblLevel.text = [NSString stringWithFormat:@"%d", count];

    tfLeftTime.text=[NSString stringWithFormat:@"%d",ANSWER_TIME];

    tmLeftTime=[[NSTimer alloc] init];
    tmLeftTime=[NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(updateLeftTime:) userInfo:nil repeats:YES];
    [self playMusic];

}
- (void)updateLeftTime:(NSTimer *)theTimer {
    static int timeCounter=1;
    timeCounter+=1;
    tfLeftTime.text=[NSString stringWithFormat:@"%d", (ANSWER_TIME-timeCounter)];
}
Run Code Online (Sandbox Code Playgroud)

iphone static timer objective-c

5
推荐指数
2
解决办法
8346
查看次数

在strrev函数实现中获得"分段失败"错误

void main() { 
    void strrev(char *); 
    char *p="GOOd";
    strrev(p);
    printf("%s",p);
}

void strrev(char *str) { 
    char temp, *end_ptr;
    if( str == NULL || !(*str) ) return;
    end_ptr = str + strlen(str) - 1;

    while( end_ptr > str ) 
    { 
        temp = *str; 
        *str = *end_ptr; 
        *end_ptr = temp; str++; 
        end_ptr--; 
    } 
}
Run Code Online (Sandbox Code Playgroud)

我得到错误分割失败可以任何人帮助我如何解决它...

c

5
推荐指数
2
解决办法
705
查看次数

检查2个阵列是否相似而不进行散列或排序

我们需要检查2个阵列是否相似.元素也可以是重复的.例如,A = {2,3,4,5,6,6}和B = {3,6,2,4,6,5}是相似的.

我有一个天真的解决方案:

foreach i:int in arr1
 foreach j:int in arr2
  {
    if(i == j)
     j = -1;
  } 
Run Code Online (Sandbox Code Playgroud)

现在,如果j的所有元素都是-1,那么我们可以说2个数组是相似的.有人可以提供一个不起作用的测试用例(我希望它应该工作!)?

这也是O(n ^ 2).我们可以做得更好吗?不允许排序和散列.

language-agnostic algorithm

5
推荐指数
2
解决办法
407
查看次数